Biostats Term Companion6450-OL · Fall 2026

Fifteen weeks of biostatistics, one week at a time.

Every week opens with problems to try, each with a fully worked solution you unfold once you are stuck. Then the written explanation of how it works, the ideas to look up, and what is due. Built from the course schedule and the two textbooks behind it — no videos required.

Right now
15Weeks
83Concepts
97Resource links
Sept 8Term starts
Dec 20Term ends

The term

Week by week

Work top to bottom: try the problems, unfold a solution when you get stuck, then read How it works for the mechanics and use Look up an idea as the index. Every number in every solution is computed, not typed. The amber band marks whichever week today falls in.

01 Sep 8–13

Introduction & data summaries

Vocabulary and description. No inference yet — the job is to say what a data set is and describe it honestly.

Try these first

Have a go before opening the solution. Getting stuck is the point — it tells you which idea below to go and read.

  1. 1
    Classify the study
    A hospital reviews records for 2,480 patients admitted with pneumonia. For each patient they record age (years), sex, insurance type (none / public / private), length of stay (nights), and whether the patient was readmitted within 30 days. They report that patients with no insurance were readmitted more often.

    (a) Classify each of the five variables. (b) Which is the explanatory variable and which the response? (c) Is this observational or experimental? (d) Can the hospital conclude that lacking insurance causes readmission?

    UsesVariable typesCases, variables, and the data matrixObservational vs experimentalConfounding variablesThe two 'randoms'

    Work it through
    1. Age — numerical, continuous. Length of stay — numerical, discrete (whole nights). Sex — categorical, nominal. Insurance type — categorical; you could argue ordinal (none < public < private) but nominal is the safer answer unless the question implies an ordering.
    2. Readmitted within 30 days — categorical, nominal, with two levels. A yes/no variable is categorical even when it is stored as 0/1.
    3. Insurance type is the explanatory variable, readmission the response — that is the direction the hospital suspects.
    4. It is observational. Nobody assigned patients to an insurance type; the researchers only recorded what was already true.
    5. So no causal claim. A confounder is easy to name: income. Lower income makes a patient both more likely to be uninsured and more likely to face the transport, medication and housing problems that drive readmission.

    AnswerAssociation only. Without random assignment the hospital can say uninsured patients were readmitted more often, not that the lack of insurance caused it.

    Where this goes wrongA confounder has to be linked to both variables. Naming one that touches only readmission earns nothing.

  2. 2
    Summarize a skewed sample
    Twelve patients' lengths of stay, in nights, are listed below. Compute the mean, median, standard deviation, Q1, Q3 and IQR. Identify any outliers using the 1.5×IQR rule. Then say which measure of centre and spread you would report, and why.
    1, 2, 2, 3, 3, 3, 4, 4, 5, 6, 7, 21

    UsesDescribing a distributionMean/SD vs median/IQRBox plots and the 1.5xIQR rule

    Work it through
    1. Mean: the values sum to 61, so x̄ = 61/12 = 5.08 nights.
    2. Median: with 12 values the middle two are the 6th and 7th, 3 and 4, so the median is 3.5 nights.
    3. Standard deviation: s = √( Σ(x−x̄)² / (n−1) ) = 5.30 nights. Divide by n−1 = 11, not by 12.
    4. Quartiles: split the ordered data at the median into two halves of six. Q1 is the median of the lower six = 2.5; Q3 is the median of the upper six = 5.5. IQR = 5.5 − 2.5 = 3.0.
    5. Fences: Q1 − 1.5×IQR = -2.00 and Q3 + 1.5×IQR = 10.00. The value 21 is above the upper fence, so it is flagged as an outlier. Nothing falls below the lower fence.
    6. The distribution is right-skewed with one extreme value, so report the median (3.5 nights) and IQR (3.0) — the robust pair.
    7. See how much the outlier moves things: drop the 21 and the mean falls from 5.08 to 3.64, while the median only moves from 3.5 to 3.0. That gap is what “robust” means.

    Answerx̄ = 5.08, median = 3.5, s = 5.30, Q1 = 2.5, Q3 = 5.5, IQR = 3.0. 21 is an outlier. Report median and IQR.

    Where this goes wrongDividing by n instead of n−1 gives 5.07 — a plausible-looking wrong answer.

  3. 3
    Row proportions or column proportions?
    Of 480 patients, 200 were uninsured and 280 insured. 34 of the uninsured and 21 of the insured were readmitted within 30 days.

    (a) Build the contingency table. (b) What proportion of uninsured patients were readmitted? (c) What proportion of readmitted patients were uninsured? (d) Which of those two answers is the one the hospital's claim needs?
                    Readmitted   Not        Total
    Uninsured             34      166         200
    Insured               21      259         280
    Total                 55      425         480

    UsesContingency tables, row vs column proportionsCases, variables, and the data matrix

    Work it through
    1. (b) conditions on being uninsured, so divide by the uninsured row total: 34/200 = 17.0%.
    2. (c) conditions on having been readmitted, so divide by the readmitted column total: 34/55 = 61.8%.
    3. Same cell, 34, two completely different numbers — 17.0% and 61.8% — because they are divided by different totals.
    4. The claim is “uninsured patients are readmitted more often”, which compares readmission rates between insurance groups. That needs (b), the row proportion — and its comparison: insured readmission is 21/280 = 7.5%.

    Answer(b) 17.0% of uninsured patients were readmitted. (c) 61.8% of readmitted patients were uninsured. The claim needs (b): 17.0% vs 7.5% for insured patients.

    Where this goes wrongReading the question for what is held fixed is the whole skill. “Of the uninsured…” fixes the row; “of those readmitted…” fixes the column.

How it worksthe written version — read this instead of watching anything

This week is vocabulary, and the vocabulary is load-bearing: almost every later mistake traces back to misreading what kind of variable or what kind of study you have.

Start with the data matrix. Rows are cases, columns are variables, and n is the number of rows. Every variable is either numerical (arithmetic on the values means something) or categorical (it takes one of a set of labels). The test is not whether the value looks like a number — a zip code is stored as digits but averaging zip codes is nonsense, so it is categorical.

Describing a distribution takes four things, every time: shape, centre, spread, and unusual observations. Skew is named for the tail, so a distribution with a long right tail is right-skewed even though most of the data sits on the left.

Which summary you report follows from the shape. For roughly symmetric data use the mean and standard deviation. When the data are skewed or contain outliers, use the median and IQR — these are the robust statistics, meaning they barely move when one extreme value is added. Watch this in problem 2: dropping a single outlier moves the mean by more than a night while the median shifts by half of one.

The standard deviation divides by n − 1, not n. That is the sample standard deviation, and it is what every formula in this course expects. Box-plot whiskers reach the furthest point within 1.5×IQR of the box; anything past that is flagged as a suspected outlier — flagged, not deleted.

For two categorical variables, a contingency table cross-tabulates counts. Row proportions and column proportions answer different questions. Read the question for what is being held fixed: “of the uninsured…” fixes the row, “of those readmitted…” fixes the column.

Look up an idea

  1. Cases, variables, and the data matrix

    Rows are cases, columns are variables. n is the number of rows — getting this straight now prevents df errors later.

  2. Variable types

    Numerical (discrete / continuous) vs categorical (nominal / ordinal). A zip code is categorical — test it by asking whether arithmetic on the values means anything.

  3. Describing a distribution

    Four things every time: shape, centre, spread, unusual observations. Skew is named for the tail, not the bulk.

  4. Mean/SD vs median/IQR

    Mean and SD for symmetric data; median and IQR when skewed or when outliers are present. The robust pair barely moves when an extreme value is added.

  5. Box plots and the 1.5xIQR rule

    Whiskers reach the furthest point within 1.5xIQR of the box; anything past that is flagged as a suspected outlier.

  6. Contingency tables, row vs column proportions

    Which proportion you want depends on what the question holds fixed. Read the question for the conditioning group.

  7. Simulation-based inference (the case study)

    Shuffle the group labels many times and see how often chance alone produces a difference this big. Every p-value later in the course answers exactly this question with a formula instead of a shuffle.

02 Sep 14–20

Sampling, random variables & population distributions

How data gets collected, and the two distributions the rest of the course leans on.

Try these first

Have a go before opening the solution. Getting stuck is the point — it tells you which idea below to go and read.

  1. 1
    Work a normal distribution in both directions
    Systolic blood pressure in a population of adults is approximately normal with μ = 138 mmHg and σ = 18 mmHg.

    (a) What proportion are below 120? (b) What proportion are above 160? (c) What proportion are between 120 and 160? (d) Above what value do the highest 10% fall?

    UsesThe normal distribution and Z-scoresReading normal tables in both directionsContinuous distributions and density

    Work it through
    1. Sketch the curve, mark 138 in the middle, mark 120 and 160, and shade. Do this first — it tells you whether each answer should be above or below 0.5.
    2. (a) Z = (120 − 138)/18 = -1.00. The table gives area to the left directly: 0.1587.
    3. (b) Z = (160 − 138)/18 = 1.2222. The table gives 0.8892 to the left, so the right tail is 1 − 0.8892 = 0.1108.
    4. (c) Between = (area left of 160) − (area left of 120) = 0.8892 − 0.1587 = 0.7305.
    5. (d) Run it backwards. The highest 10% sit above the 90th percentile, and the Z with 0.90 below it is 1.2816. Then x = μ + Zσ = 138 + 1.2816×18 = 161.1 mmHg.

    Answer(a) 0.1587 (b) 0.1108 (c) 0.7305 (d) about 161.1 mmHg.

    Where this goes wrongTables give area to the LEFT. Reporting 0.8892 as the answer to (b) is the single most common slip.

  2. 2
    Is it binomial, and then compute
    A clinic's records show 30% of patients miss their first follow-up appointment. Twelve patients are booked for Thursday, and they are unrelated to one another.

    (a) Check the four binomial conditions. (b) P(exactly 3 miss)? (c) P(at least one misses)? (d) Mean and SD of the number who miss?

    UsesThe binomial distribution

    Work it through
    1. (a) Independent — stated, the patients are unrelated. n fixed — 12 appointments. Success/failure — misses or attends. p constant — 0.30 for each. All four hold.
    2. (b) P(X = 3) = C(12,3) × 0.30³ × 0.70⁹ = 220 × 0.0270 × 0.040354 = 0.2397.
    3. (c) Going through P(1) + P(2) + … + P(12) is eleven terms. Use the complement instead: P(at least 1) = 1 − P(0) = 1 − 0.70¹² = 1 − 0.01384 = 0.9862.
    4. (d) μ = np = 12×0.30 = 3.6. σ = √(np(1−p)) = √(2.52) = 1.587.

    Answer(b) 0.2397 (c) 0.9862 (d) μ = 3.6 patients, σ = 1.587.

    Where this goes wrongForgetting C(12,3) = 220 and computing only 0.30³×0.70⁹ gives 0.001090 — far too small.

  3. 3
    Pick the sampling scheme, then spot the bias
    A health department wants the share of county adults who had a flu shot. Four proposals:

    (A) Draw 600 names at random from the county voter roll.
    (B) Split the county into its 5 age bands, draw 120 at random from each.
    (C) Pick 8 of the county's 90 neighbourhoods at random, survey every adult in those 8.
    (D) Post a survey link on the department's social media and take the first 5,000 responses.

    (a) Name each scheme. (b) Which gives a biased estimate, and why? (c) Would 50,000 responses fix (D)? (d) In (A), what is the population, the sample, the parameter and the statistic?

    UsesFour sampling methodsBias, and why a bigger sample cannot fix itPopulation vs sample, parameter vs statistic

    Work it through
    1. (a) A is a simple random sample. B is stratified — age bands are internally similar and differ from each other, and sampling within each guarantees every band is represented. C is cluster sampling — neighbourhoods are each a small mixed version of the county, so you take whole ones. D is a convenience sample.
    2. (b) D is biased, and badly. Only people who follow the department and care enough to click will answer — a group far more health-engaged than the county. The estimate will run high. A is also mildly biased: the voter roll excludes non-registered adults, who differ systematically. Worth stating even though A is the best of the four.
    3. (c) No. Bias is systematic, so more responses shrink the margin of error while leaving the estimate centred on the wrong value. 50,000 self-selected responses give a very precise wrong answer — and the tiny margin of error makes it look more trustworthy, not less.
    4. (d) Population: all adults in the county. Sample: the 600 surveyed. Parameter: p, the true county vaccination rate — unknown and fixed. Statistic: p̂, the share vaccinated among the 600 — known exactly, and different if you drew 600 other names.

    Answer(a) simple random, stratified, cluster, convenience. (b) D is badly biased by self-selection; A is mildly biased by the voter roll. (c) No — a bigger biased sample is a precise wrong answer. (d) Population: county adults; sample: the 600; parameter: p; statistic: p̂.

    Where this goes wrongA large n is reassuring and mostly irrelevant. A random sample of 600 beats a self-selected 50,000 every time.

  4. 4
    Normal approximation, with the correction
    The same clinic books 200 patients in a month, still with p = 0.30 missing. Use the normal approximation to estimate P(at least 54 miss). Check that the approximation is allowed, and apply the continuity correction.

    UsesNormal approximation to the binomialThe normal distribution and Z-scores

    Work it through
    1. Check first: np = 200×0.30 = 60 and n(1−p) = 140. Both are comfortably ≥ 10, so the normal approximation is appropriate.
    2. Parameters: μ = np = 60, σ = √(np(1−p)) = 6.4807.
    3. Continuity correction: “at least 54” means the bars from 54 upward, and each bar is a unit wide centred on its integer. The smooth curve should start at the bar's left edge, 53.5, not at 54.
    4. Z = (53.5 − 60)/6.4807 = -1.0030, so P = 0.8421.
    5. Without the correction you would get Z = -0.9258 and P = 0.8227 — close here because n is large, but the correction matters much more on narrow intervals.

    AnswerAbout 0.8421, or a 84.2% chance that at least 54 of the 200 patients miss.

    Where this goes wrongCorrecting the wrong way. Lower cutoffs go DOWN by 0.5, upper cutoffs go UP by 0.5 — you always widen the region.

How it worksthe written version — read this instead of watching anything

Two separate ideas share this week: where data comes from, and the two distributions everything later leans on.

Sampling. A parameter (μ, p) is the unknown truth about a population; a statistic (x̄, p̂) is what you computed from a sample. The four schemes are worth memorising by their contrast: in a stratum the cases are similar to each other and the strata differ; in a cluster the cases are varied and the clusters resemble one another. Simple random sampling is the baseline; multistage samples within chosen clusters.

Bias is systematic error, and the crucial fact is that a bigger sample does not fix it. Survey 10,000 people through a convenience sample and you get a very precise wrong answer. Only better sampling fixes bias; more data fixes only imprecision.

The normal distribution is described entirely by μ and σ. The Z-score, Z = (x − μ)/σ, says how many standard deviations x sits above or below the mean, which lets one table serve every normal distribution. Two habits make this reliable: always sketch the curve and shade the region first, and remember tables give area to the left — the right tail is 1 minus the table value. To go backwards from a percentile, find the probability inside the table, read off Z, then x = μ + Zσ.

The binomial counts successes in a fixed number of independent trials, and needs four things: independent trials, n fixed, success/failure outcomes, and p constant. P(k) = C(n,k)pk(1−p)n−k, with μ = np and σ = √(np(1−p)). For “at least one”, use the complement: 1 − P(0). When np ≥ 10 and n(1−p) ≥ 10, the binomial is close to normal — and that condition comes back next week wearing a different name.

Look up an idea

  1. Population vs sample, parameter vs statistic

    Greek letters are the unknown truth; hats and bars are what you computed. Hypotheses are always about parameters.

  2. Four sampling methods

    Simple random, stratified, cluster, multistage. Within a stratum cases are similar; within a cluster they are varied and the clusters resemble each other.

  3. Bias, and why a bigger sample cannot fix it

    Convenience samples, non-response bias, anecdotal evidence. Bias is systematic — a larger sample just gives a precise wrong answer.

  4. Continuous distributions and density

    Probability is area under the curve, and the total area is 1. The probability of any single exact value is zero.

  5. The normal distribution and Z-scores

    Z = (x — μ)/σ is how many SDs from the mean. Standardizing lets one table serve every normal distribution.

  6. Reading normal tables in both directions

    Tables give area to the LEFT. Right tail = 1 — left. Given a percentile, run it backwards: find the probability inside the table, read off Z, then x = μ + Z*σ.

  7. The binomial distribution

    Successes in a fixed number of independent trials. Four conditions: independent, n fixed, success/failure, p constant.

  8. Normal approximation to the binomial

    Valid when np ≥ 10 and n(1-p) ≥ 10 — the same requirement that becomes the success-failure condition in week 3.

03 Sep 21–27

Confidence intervals for a proportion

The single most important week in the course. Everything from here to week 14 is this same skeleton with a different standard error.

Try these first

Have a go before opening the solution. Getting stuck is the point — it tells you which idea below to go and read.

  1. 1
    Build and interpret a proportion interval
    In a random sample of 400 adults from a county, 148 report having had a flu vaccination this season. Build a 95% confidence interval for the county's vaccination rate, check the conditions, and write the interpretation sentence.

    UsesSampling distributionStandard error vs standard deviationCentral Limit Theorem for a proportionThe two conditionsThe interval, and the margin of errorWhat '95% confident' actually means

    Work it through
    1. Prepare. p̂ = 148/400 = 0.370, n = 400, 95% confidence.
    2. Check. Independence: a random sample, and 400 is far under 10% of a county's adults. Success–failure: 148 successes and 252 failures, both ≥ 10. Conditions met.
    3. Calculate. SE = √(p̂(1−p̂)/n) = √(0.370×0.630/400) = 0.02414.
    4. z* for 95% is 1.96, so the margin of error is 1.96×0.02414 = 0.04731 — about 4.7 percentage points.
    5. Interval: 0.370 ± 0.0473 = (0.3227, 0.4173).
    6. Conclude. “We are 95% confident that the true proportion of adults in this county who were vaccinated this season is between 32.3% and 41.7%.” Name the confidence level, the population, and the quantity.

    Answer(0.3227, 0.4173), or about 32.3% to 41.7%.

    Where this goes wrong“There is a 95% probability the true rate is in this interval” is wrong. The rate is a fixed number; the 95% describes the procedure across repeated samples.

  2. 2
    How many people do we need?
    The county wants next year's estimate accurate to within ±3 percentage points at 95% confidence.

    (a) How large a sample is needed with no prior information? (b) How large if this year's estimate of 0.370 is used as the planning value? (c) Why is the answer to (a) larger?

    UsesChoosing a sample sizeThe interval, and the margin of error

    Work it through
    1. The margin of error is z*√(p(1−p)/n). Set it equal to the target and solve: n ≥ p(1−p)(z*/ME)².
    2. (a) With no prior estimate use p = 0.5, which makes p(1−p) as large as it can be (0.25) and so gives the safest n. n ≥ 0.25×(1.96/0.03)² = 1067.1 → round up to 1068.
    3. (b) With p = 0.370: n ≥ 0.370×0.630×(1.96/0.03)² = 994.9 → round up to 995.
    4. (c) p(1−p) peaks at p = 0.5. Since 0.370 is away from 0.5, the true variance is smaller and fewer people are needed. Using 0.5 is the conservative choice when you know nothing.
    5. Always round up. Rounding 994.9 down to 994 would miss the target margin of error.

    Answer(a) 1068 people. (b) 995 people.

    Where this goes wrongHalving the margin of error quadruples n — the ME depends on 1/√n, so precision is expensive.

  3. 3
    Find the wrong interpretations
    A study reports a 95% confidence interval of (0.32, 0.42) for the proportion of a city's residents with untreated high blood pressure. Four statements follow. Say which are wrong and exactly why.

    (1) There is a 95% probability the true proportion is between 0.32 and 0.42.
    (2) 95% of residents have a rate between 0.32 and 0.42.
    (3) If the study were repeated many times, about 95% of the intervals produced would contain the true proportion.
    (4) We are 95% confident the sample proportion is between 0.32 and 0.42.

    UsesWhat '95% confident' actually means

    Work it through
    1. (1) Wrong. The true proportion is a fixed number — it is either inside this interval or it is not. The 95% is a property of the method, not of this one interval.
    2. (2) Wrong. That describes individual residents. A confidence interval is about a single population parameter, not the spread of individuals. Individuals do not each have a “rate” here at all.
    3. (3) Correct. This is the definition: repeat the whole study many times and about 95% of the intervals built this way capture the truth.
    4. (4) Wrong. The sample proportion is 0.37 — the centre of the interval, and known exactly. There is nothing to be uncertain about. Confidence intervals are always about the population parameter.

    AnswerOnly (3) is correct. (1) treats a fixed parameter as random, (2) describes individuals rather than a parameter, and (4) is about the sample rather than the population.

    Where this goes wrongStatement (1) is the one almost everyone accepts. Read it carefully every time.

How it worksthe written version — read this instead of watching anything

This is the most important week in the course. Everything from here to week 14 is this same skeleton with a different standard error, so time spent here pays back five times over.

A point estimate (p̂) is one sample's answer. Take a different sample and you get a different number — that is sampling variability, not a mistake. The sampling distribution is the distribution of the estimate across all possible samples of that size. You never observe it; you reason about it.

The standard error is the standard deviation of that sampling distribution. This is the distinction people lose: s describes the spread of the data; SE describes the spread of the estimate, and SE shrinks like 1/√n. Every confidence interval and every test statistic uses SE, never s.

The Central Limit Theorem says that with independence and a large enough sample, p̂ is nearly normal, centred at p, with SE = √(p(1−p)/n). Two conditions: independence (a random sample, or random assignment; and n under 10% of the population if sampling without replacement) and success–failure (at least 10 successes and 10 failures).

Then the interval is just point estimate ± z* × SE, with z* = 1.96 at 95%. The half-width z*×SE is the margin of error.

The interpretation is where marks are won and lost. “95% confident” is a property of the procedure: repeat the whole study many times and about 95% of the intervals built this way capture the truth. It is not a 95% probability that this particular interval contains the parameter — the parameter is a fixed number, and this interval either contains it or does not. Problem 3 is nothing but that distinction, and it is worth doing slowly.

Look up an idea

  1. Sampling distribution

    The distribution of a statistic across all possible samples. Never observed — always reasoned about.

  2. Standard error vs standard deviation

    s is the spread of the DATA. SE is the spread of the ESTIMATE, and shrinks like 1/√(n). Intervals always use SE.

  3. Central Limit Theorem for a proportion

    With independence and a large enough sample, p̂ is nearly normal around p with SE = √(p(1-p)/n).

  4. The two conditions

    Independence (random sample or random assignment; n < 10% of the population) and success-failure (at least 10 successes and 10 failures).

  5. The interval, and the margin of error

    point estimate ± z* x SE. The margin of error is z* x SE — half the interval's width.

  6. What '95% confident' actually means

    A property of the PROCEDURE: repeat the study many times and about 95% of the intervals built this way capture the truth. Not a probability about this one interval.

  7. Choosing a sample size

    n ≥ p(1-p)(z*/ME)². Use p = 0.5 with no prior estimate — it maximises p(1-p) and gives the safest n. Always round up.

04 Sep 28 – Oct 4

Confidence intervals for a mean

Same skeleton as week 3, but σ is unknown — so t replaces z and degrees of freedom appear.

Try these first

Have a go before opening the solution. Getting stuck is the point — it tells you which idea below to go and read.

  1. 1
    A t-interval for a mean
    Fifteen patients on a new inhaler record the number of symptom-free days in a 14-day window. The sample mean is 7.4 days with s = 2.1 days, and a box plot shows no outliers. Build a 95% confidence interval for the population mean.

    UsesCLT for the sample meanWhy t instead of zDegrees of freedomThe normality conditionThe t-intervalStandard error vs standard deviation

    Work it through
    1. Prepare. x̄ = 7.4, s = 2.1, n = 15, 95% confidence.
    2. Check. Independence: assume the 15 patients are a random sample. Normality: n = 15 is under 30, so we need no clear outliers — the box plot confirms that, so we assume the population is nearly normal.
    3. Calculate. SE = s/√n = 2.1/√15 = 0.5422.
    4. df = n − 1 = 14. From the t-table, t* for 95% with 14 df is 2.145.
    5. Interval: 7.4 ± 2.145×0.5422 = 7.4 ± 1.163 = (6.24, 8.56) days.
    6. Conclude. “We are 95% confident that the true mean number of symptom-free days for patients on this inhaler is between 6.24 and 8.56 days.”

    Answer(6.24, 8.56) days.

    Where this goes wrongUsing z* = 1.96 instead of t* = 2.145 gives (6.34, 8.46) — too narrow. With σ unknown you always use t, however large n is.

  2. 2
    What actually makes an interval narrower?
    Keeping x̄ = 7.4 and s = 2.1 fixed, work out the margin of error at 95% confidence for n = 15, 30, 60 and 120. Then compute the margin of error at 99% confidence with n = 15. Which lever does more, and what does each one cost?

    UsesThe t-intervalDegrees of freedom

    Work it through
    1. n = 15: t* = 2.145, SE = 0.5422, ME = 1.1629, width = 2.3259
    2. n = 30: t* = 2.045, SE = 0.3834, ME = 0.7842, width = 1.5683
    3. n = 60: t* = 2.001, SE = 0.2711, ME = 0.5425, width = 1.0850
    4. n = 120: t* = 1.980, SE = 0.1917, ME = 0.3796, width = 0.7592
    5. Quadrupling n from 15 to 60 roughly halves the margin of error (1.1629 → 0.5425) — the √n in the denominator means you buy precision at a square-law price.
    6. Now raise confidence instead. At 99% with n = 15, t* rises from 2.145 to 2.977, so ME grows from 1.1629 to 1.6141. More confidence buys a wider, less useful interval.

    AnswerSample size is the only lever that improves precision. Raising the confidence level widens the interval; lowering it narrows the interval but weakens the claim.

    Where this goes wrong“Be more confident” sounds like an improvement. It is a trade: a 99% interval says less about where the parameter is.

How it worksthe written version — read this instead of watching anything

Same skeleton as last week, one complication: for a mean, σ is unknown.

The CLT for means says x̄ is nearly normal around μ with SE = σ/√n. But you never know σ, so you substitute s — and that substitution adds uncertainty the normal model does not account for. The t-distribution fixes it. Same bell shape, thicker tails, so critical values are larger and intervals come out wider. That extra width is the honest price of not knowing σ.

The shape is set by the degrees of freedom, and for one sample df = n − 1. Larger df means closer to normal; past about df = 30 they are nearly indistinguishable. But the rule is about what you know, not about size: if σ is unknown you use t, however large n is. Since σ is essentially always unknown in practice, you will use t for every mean in this course.

The interval is x̄ ± t*df × s/√n, built in the same four steps as week 3 — prepare, check, calculate, conclude.

The normality condition has two rules of thumb. With n < 30, you need no clear outliers, and you assume the population is nearly normal. With n ≥ 30, you need no particularly extreme outliers; the CLT absorbs moderate skew. Judge this from a histogram or box plot — never from n alone.

Problem 2 is worth doing even though it looks like arithmetic busywork. It shows that sample size is the only lever that genuinely improves precision, and it costs a square law: quadrupling n only halves the margin of error. Raising the confidence level does not improve anything — it widens the interval, which means the interval says less about where the parameter is.

Look up an idea

  1. CLT for the sample mean

    x̄ is nearly normal around μ with SE = σ/√(n).

  2. Why t instead of z

    Substituting s for the unknown σ adds uncertainty. The t-distribution has thicker tails to account for it, so intervals come out wider.

  3. Degrees of freedom

    df = n — 1 for one sample. Larger df means closer to normal. A wrong df is a silent error — the p-value still looks plausible.

  4. The normality condition

    n < 30: require no clear outliers and assume a nearly normal population. n ≥ 30: require no particularly extreme outliers; the CLT absorbs moderate skew. Judge from a plot, not from n.

  5. The t-interval

    x̄ ± t*_df x s/√(n). Same four steps as week 3: prepare, check, calculate, conclude.

05 Oct 5–11

Introduction to hypothesis testing

The other half of inference. Three sections at once — proportions, one-sample t-tests, and paired data.

Try these first

Have a go before opening the solution. Getting stuck is the point — it tells you which idea below to go and read.

  1. 1
    A one-proportion test (mind the standard error)
    Nationally 32% of adults skip their annual check-up. A clinic surveys 250 of its own patients and finds 96 skipped theirs. At α = 0.05, is the clinic's rate different from the national rate? Show the hypotheses, the check, the statistic and the conclusion.

    UsesH0 and HAA test uses p0, a CI uses p̂The p-valueOne-sided vs two-sided

    Work it through
    1. Hypotheses. H₀: p = 0.32 (the clinic matches the national rate). Hₐ: p ≠ 0.32. Two-sided — the question asks “different”, not “higher”. Note both are about p, the population proportion, never p̂.
    2. Check. Under H₀ we expect np₀ = 250×0.32 = 80 successes and n(1−p₀) = 170 failures. Both ≥ 10, so p̂ is nearly normal.
    3. Calculate. p̂ = 96/250 = 0.384. The test supposes H₀ is true, so build SE from the null value: SE = √(0.32×0.68/250) = 0.02950.
    4. Z = (p̂ − p₀)/SE = (0.384 − 0.32)/0.02950 = 2.169.
    5. Two-sided p-value = 2×P(Z > 2.169) = 0.0301.
    6. Conclude. 0.0301 < 0.05, so we reject H₀. The data provide strong evidence that this clinic's skip rate (38.4%) differs from the national 32%.
    7. Worth noticing how close this is. At α = 0.05 it rejects; at α = 0.01 it would not. When a p-value sits this near the threshold, say so rather than reporting a bare “significant”.

    AnswerZ = 2.169, p = 0.0301. Reject H₀ — evidence that the clinic's rate differs from 32%.

    Where this goes wrongUsing p̂ in the SE gives SE = 0.03076, Z = 2.081 and p = 0.0375 instead of 0.0301 — the same verdict here, but a different number answering a different question. A test uses p₀; only a confidence interval uses p̂.

  2. 2
    Paired data, done properly
    Ten patients have their systolic blood pressure measured before and after eight weeks on a low-sodium diet. Test whether the diet changed blood pressure, at α = 0.05, and give a 95% confidence interval for the mean change.
    Patient   1    2    3    4    5    6    7    8    9   10
    Before  151  143  168  155  139  162  147  158  171  149
    After   144  138  159  149  137  152  143  150  160  145

    UsesPaired dataH0 and HAThe p-value

    Work it through
    1. These are paired: each “after” belongs to a specific patient's “before”. So work with the differences and run a one-sample t.
    2. Differences (before − after): 7, 5, 9, 6, 2, 10, 4, 8, 11, 4.
    3. d̄ = 6.60 mmHg, s_d = 2.914, n = 10 pairs.
    4. Hypotheses. H₀: μ_d = 0 (no change). Hₐ: μ_d ≠ 0.
    5. Check. The 10 patients are independent of one another, and the differences show no outliers, so with n < 30 we assume they are nearly normal.
    6. SE = s_d/√n = 2.914/√10 = 0.9214, and df = 10 − 1 = 9.
    7. t = (d̄ − 0)/SE = 6.60/0.9214 = 7.163, giving p = 5.29e-05.
    8. Interval: t* for 95% with 9 df is 2.262, so 6.60 ± 2.262×0.9214 = (4.52, 8.68) mmHg.
    9. Conclude. p is far below 0.05, so reject H₀. The data provide strong evidence that mean systolic blood pressure fell, by somewhere between 4.52 and 8.68 mmHg on average.

    Answerd̄ = 6.60 mmHg, t = 7.163 on 9 df, p = 5.29e-05. Reject H₀; 95% CI (4.52, 8.68) mmHg.

    Where this goes wrongTreating these as two independent samples of 10 gives t = 1.590 on about 9–18 df instead of t = 7.163 on 9 df — a far weaker result, because it throws away the pairing that removes patient-to-patient variation.

  3. 3
    Which error is worse?
    For each scenario, say what a Type 1 error and a Type 2 error would be in context, and whether you would choose a smaller or larger α.

    (a) Screening donated blood for an infection.
    (b) Testing whether an expensive new drug beats a cheap, well-tolerated standard one.

    UsesType 1 and Type 2 errorsH0 and HA

    Work it through
    1. (a) H₀: the unit is clean. Type 1 — discard a clean unit. Costly but recoverable. Type 2 — release an infected unit to a patient. Potentially fatal.
    2. Type 2 is far worse here, so you want the test to trigger easily: choose a larger α. You accept more false alarms to avoid misses.
    3. (b) H₀: the new drug is no better. Type 1 — adopt an expensive drug that is not actually better, wasting money and exposing patients to a new side-effect profile for nothing. Type 2 — miss a genuine improvement.
    4. Here Type 1 carries the larger cost, so choose a smaller α — demand stronger evidence before switching.
    5. The general rule: α is the Type 1 error rate you are willing to accept. Lowering it always raises the Type 2 rate. There is no setting that reduces both — only a bigger sample does that.

    Answer(a) larger α — a missed infection is worse than a discarded unit. (b) smaller α — adopting a costly drug that does not work is worse than missing a modest gain.

    Where this goes wrongα = 0.05 is a convention, not a law. Exams ask you to justify departing from it.

How it worksthe written version — read this instead of watching anything

Confidence intervals estimate. Hypothesis tests decide. Same machinery, different question.

H₀ is the skeptical position — no effect, no difference, status quo — and is always an equality at the null value. Hₐ is the claim that needs evidence. Both are statements about parameters (p, μ), never about statistics: there is nothing to hypothesise about p̂ because you measured it.

The p-value is the probability of data at least as extreme as what you saw, computed assuming H₀ is true. A small p-value means the data would be surprising under H₀, which is evidence against it. It is not the probability that H₀ is true, and not the probability you made a mistake.

Here is the detail that separates a test from an interval, and it is worth saying slowly. A test supposes H₀ is true, so it builds the standard error from the null value p₀: SE = √(p₀(1−p₀)/n). A confidence interval supposes nothing, so it uses . Using p̂ in a test is a genuine error, not a rounding difference — problem 1 shows both numbers side by side.

The decision: p < α means reject H₀; p > α means fail to reject. Never “accept H₀”, never “proved”. Failing to reject means the evidence was not strong enough, which is not the same as evidence of no effect.

Type 1 error is rejecting a true H₀ — a false alarm, at rate α. Type 2 is failing to reject a false one — a miss. Lowering α always raises the Type 2 rate; only a bigger sample improves both. Choose α by which mistake costs more in context.

Paired data is the week's other idea and its most-missed one. If each observation has exactly one natural partner — the same patient before and after, twins, left and right arm — compute the differences and run a one-sample t on them. Thirty patients measured twice gives thirty differences and df = 29, not two samples of thirty with df = 58.

Look up an idea

  1. H0 and HA

    H0 is the skeptical position and is always an equality at the null value. Both are statements about parameters, never about statistics.

  2. The p-value

    P(data at least this extreme | H0 true). NOT the probability that H0 is true, and not the probability you made a mistake.

  3. A test uses p0, a CI uses p̂

    A test supposes H0 is true, so the standard error is built from the null value p0. This is a real error, not a rounding difference.

  4. Type 1 and Type 2 errors

    Type 1 is a false alarm (rate α), Type 2 is a miss (rate β). Lowering α necessarily raises the Type 2 rate — choose by which mistake costs more.

  5. One-sided vs two-sided

    Decide from the research question BEFORE seeing the data. Choosing one-sided after seeing the direction doubles the real Type 1 error rate.

  6. Paired data

    Each observation has exactly one partner. Compute the differences, then run a ONE-sample t on them. n is the number of pairs.

06 Oct 12–18

Inferential methods for comparing means

Two independent groups. One section, so a good week to consolidate weeks 3-5.

Try these first

Have a go before opening the solution. Getting stuck is the point — it tells you which idea below to go and read.

  1. 1
    Two independent means
    A trial randomly assigns patients to a new physiotherapy protocol or the standard one, and records days to recovery.
    New: n = 42, x̄ = 8.6 days, s = 3.1.
    Standard: n = 38, x̄ = 10.9 days, s = 3.8.

    Test whether the mean recovery times differ at α = 0.05, and give a 95% confidence interval for the difference.

    UsesThe two-sample t procedureDegrees of freedom, two waysConditions, checked per groupPooled standard deviationPaired or independent?

    Work it through
    1. Hypotheses. H₀: μ₁ = μ₂, i.e. the difference is 0. Hₐ: μ₁ ≠ μ₂.
    2. Check. Patients were randomly assigned, so the groups are independent within and between. Both n are ≥ 30, so with no extreme outliers the sampling distribution of the difference is nearly normal.
    3. Point estimate: x̄₁ − x̄₂ = 8.6 − 10.9 = -2.3 days.
    4. SE = √(s₁²/n₁ + s₂²/n₂) = √(0.2288 + 0.3800) = 0.7803.
    5. By hand, df = min(41, 37) = 37. t = -2.3/0.7803 = -2.948, giving p = 0.0055.
    6. Interval: t* for 95% with 37 df is 2.026, so -2.3 ± 2.026×0.7803 = (-3.88, -0.72) days.
    7. Conclude. p = 0.0055 < 0.05, so reject H₀. The data provide strong evidence that the new protocol has a shorter mean recovery time — by roughly 0.72 to 3.88 days. Note the interval excludes 0, which agrees with the test.
    8. Software would use the Welch df of 71.6 and report p = 0.0043 — almost identical. Say which df you used.

    Answert = -2.948 on 37 df, p = 0.0055. Reject H₀; 95% CI for the difference (-3.88, -0.72) days.

    Where this goes wrongBecause this was a randomized experiment, a causal claim IS allowed here — the protocol shortened recovery. That is unusual and comes only from the random assignment.

  2. 2
    Paired or independent?
    For each study, say whether the data are paired or independent, and give the degrees of freedom you would use.

    (a) 40 patients have cholesterol measured before and after 12 weeks on a statin.
    (b) 40 patients get a statin and 40 different patients get a placebo; cholesterol is measured at 12 weeks.
    (c) 25 pairs of siblings, one randomly assigned to each of two diets.
    (d) Systolic pressure in the left and right arm of 30 patients.
    (e) Recovery times in 60 patients at hospital A and 45 at hospital B.

    UsesPaired or independent?Degrees of freedom, two ways

    Work it through
    1. (a) Paired — the same person twice. 40 differences, df = 39.
    2. (b) Independent — two separate groups of people. By hand df = min(39, 39) = 39 (software would give ~78).
    3. (c) Paired — siblings are matched deliberately, which is the point of the design. 25 differences, df = 24.
    4. (d) Paired — two measurements on the same body. 30 differences, df = 29.
    5. (e) Independent — different patients at different hospitals. By hand df = min(59, 44) = 44.
    6. The test: could you shuffle one column without breaking anything? In (a), (c) and (d) shuffling destroys a real correspondence, so they are paired. In (b) and (e) it destroys nothing.

    AnswerPaired: (a) df 39, (c) df 24, (d) df 29. Independent: (b) df 39 by hand, (e) df 44 by hand.

    Where this goes wrong(c) catches people out. Matched pairs are paired by design even though two different people are involved.

  3. 3
    What a non-significant result actually tells you
    A small trial compares two pain treatments. The observed difference in mean pain score is 2.3 points with SE = 1.9 and df = 17. The report says: “There was no difference between the treatments (p > 0.05).” Compute the test and the interval, then rewrite the sentence correctly.

    UsesWhat a non-significant result does not meanThe two-sample t procedure

    Work it through
    1. t = 2.3/1.9 = 1.211 on 17 df, so p = 0.2426. Above 0.05, so we fail to reject H₀.
    2. Now the interval: t* for 95% with 17 df is 2.110, giving 2.3 ± 2.110×1.9 = (-1.71, 6.31).
    3. Look at what that interval contains. It includes 0, which is why the test did not reject — but it also includes a difference as large as 6.31 points. The study simply could not tell those apart.
    4. So “no difference” is not supported. The honest sentence: “The data do not provide sufficient evidence of a difference between the treatments (difference 2.3 points, 95% CI -1.71 to 6.31). The study was too small to rule out a clinically meaningful effect.”

    Answert = 1.211, p = 0.2426. Fail to reject — but the 95% CI (-1.71, 6.31) shows the study cannot rule out a large effect. Absence of evidence is not evidence of absence.

    Where this goes wrongThis is why the confidence interval belongs next to every p-value. The p-value alone hides how wide the uncertainty is.

How it worksthe written version — read this instead of watching anything

Two genuinely separate groups this week, with one decision to get right before any arithmetic.

Paired or independent? Ask whether you could shuffle one column without breaking anything. If shuffling destroys a real correspondence — the same person, matched siblings, two arms of one body — the data are paired and you work with differences. If it destroys nothing, the groups are independent. Matched pairs count as paired even though two different people are involved, which is the case that catches people out.

For two independent samples the estimate is x̄₁ − x̄₂ and the standard error is √(s₁²/n₁ + s₂²/n₂). Notice the variances add even though you are subtracting the means — comparing two noisy quantities is noisier than either one alone.

Degrees of freedom come in two flavours. By hand, use the conservative min(n₁−1, n₂−1). Software uses the Welch–Satterthwaite formula and reports a decimal. Both are acceptable — just say which you used. The by-hand version gives a slightly wider interval, which errs safe.

Conditions are checked per group: independence within and between, and normality separately in each group. Pooling the standard deviations is not the default — only do it when background knowledge says the population SDs really are equal.

The week's most valuable idea is what a non-significant result means, and problem 3 is built entirely around it. A p-value above 0.05 does not say “no difference”. It says the study could not distinguish the observed difference from zero — and the confidence interval will often show that a large, clinically important effect is still completely consistent with the data. Absence of evidence is not evidence of absence. This is why the interval belongs next to every p-value: the p-value alone hides how wide the uncertainty is.

Look up an idea

  1. The two-sample t procedure

    SE = √(s1²/n1 + s2²/n2). The estimate is the difference of the means, and the null value is 0.

  2. Degrees of freedom, two ways

    By hand use min(n1-1, n2-1), which is conservative. Software uses the Welch formula and reports a decimal. Both are fine — say which you used.

  3. Conditions, checked per group

    Independence within AND between the groups; normality checked separately in each group.

  4. Paired or independent?

    If you could shuffle one column without breaking a correspondence, they are independent. This decision comes before any arithmetic.

  5. What a non-significant result does not mean

    'Fail to reject' is not evidence of no effect. Report the confidence interval — it shows what effect sizes are still plausible.

  6. Pooled standard deviation

    Only when background knowledge says the population SDs are equal. It is not the default, and the benefit shrinks as samples grow.

07 Oct 19–25

Study design & more sampling

Back to chapter 1 with inference in hand, plus power and sample size. First week using the second textbook.

Try these first

Have a go before opening the solution. Getting stuck is the point — it tells you which idea below to go and read.

  1. 1
    Scope of inference, four ways
    For each study, say (i) whether the results generalize to a wider population and (ii) whether a causal claim is supported — with the reason for each.

    (a) 900 adults randomly sampled from a national register; researchers record exercise habits and blood pressure.
    (b) 60 volunteers from one clinic are randomly assigned to exercise or control for 12 weeks.
    (c) 1,200 adults randomly sampled nationally, then randomly assigned to two diets.
    (d) 80 patients who chose to join a gym are compared with 80 who did not.

    UsesThe two 'randoms'Observational vs experimentalConfounding variablesFour sampling methodsBias, and why a bigger sample cannot fix it

    Work it through
    1. The two questions have different answers from different mechanisms. Random sampling → generalizability. Random assignment → causality.
    2. (a) Random sample, no assignment. Generalizes to national adults; association only. Fitter people may differ in diet, age and income.
    3. (b) No random sample (volunteers at one clinic), but random assignment. Causal — for these subjects; does not generalize beyond people like them.
    4. (c) Both. Generalizes and causal — the strongest design, and rare because it is expensive.
    5. (d) Neither. Patients selected themselves into the gym. Association only, and only for these patients. Anyone who chooses to join a gym differs systematically from anyone who does not.

    Answer(a) generalizes, not causal. (b) causal, does not generalize. (c) both. (d) neither.

    Where this goes wrongGiving the same reason for both halves. Each needs its own: name the sampling for one and the assignment for the other.

  2. 2
    Critique an experimental design
    A clinic tests whether a mindfulness programme reduces chronic pain. The proposal: recruit 60 volunteers, let them choose either the programme or a waiting list, measure self-reported pain at 8 weeks, and have the programme's instructor do the scoring.

    (a) Identify every design flaw. (b) Rewrite the design applying the four principles. (c) What would blinding look like here, and why does it matter for this outcome in particular?

    UsesFour principles of experimental designBlinding and placeboObservational vs experimentalThe two 'randoms'Confounding variables

    Work it through
    1. (a) Three serious flaws. Self-selection — participants choose their group, so this is observational, not experimental, and motivation confounds everything: people who opt into mindfulness differ from those who do not. The instructor scores the outcome — they know who got the treatment and want it to work. A waiting list is not a placebo — the treated group gets attention, routine and expectation that the control group does not.
    2. (b) Control: give both groups the same amount of contact time and follow-up, so the only difference is the mindfulness content. Randomize: assign the 60 by coin flip rather than letting them choose — this is what converts the study from observational to experimental and buys a causal claim. Replicate: 60 may be too few; run the power calculation first and enrol what it says. Block: baseline pain severity strongly affects the outcome, so split into high and low severity and randomize within each block.
    3. (c) Double-blind would mean neither the participant nor the assessor knows the group. Full blinding of participants is impossible — you know whether you attended classes — so use an active control: a matched programme of equal contact time without the mindfulness component. At minimum, blind the assessor.
    4. Why it matters especially here: the outcome is self-reported pain, which is exactly the kind of measure the placebo effect moves. Combine that with an unblinded assessor who has a stake in the result, and the study can produce a positive finding with no real effect at all.

    AnswerSelf-selection (no random assignment), an unblinded invested assessor, and no real control. Fix with control, randomization, adequate replication and blocking on baseline severity, plus an active control and a blinded assessor.

    Where this goes wrongA waiting-list control is common and weak. It differs from the treatment in attention and expectation, not just in the ingredient being tested.

  3. 3
    How many patients does the trial need?
    A trial wants to detect a 5 mmHg difference in mean systolic blood pressure between two treatments. Past data suggest σ ≈ 12 mmHg in each group. Using α = 0.05 (two-sided) and 80% power, how many patients per group are needed?

    Then: what happens if you want 90% power, and what happens if the effect you care about is 10 mmHg instead of 5?

    UsesPlanning a sample sizePower

    Work it through
    1. The standard formula for comparing two means with equal group sizes: n per group = 2σ²(zα/2 + zβ)² / d².
    2. zα/2 = 1.960 (two-sided 0.05) and zβ = 0.8416 (80% power).
    3. n = 2×12²×(1.960+0.8416)² / 5² = 90.4 → 91 patients per group, so 182 in total.
    4. For 90% power, zβ rises to 1.2816, giving 122 per group — about 34% more patients for ten percentage points of power.
    5. If a 10 mmHg difference is what matters, d doubles and d² quadruples: 23 per group. Bigger effects are far cheaper to detect.
    6. Always round up, and do this before collecting data. A trial that fails to reject with n = 20 per group has told you almost nothing.

    Answer91 per group for 80% power; 122 per group for 90%; 23 per group if the target effect is 10 mmHg.

    Where this goes wrongPower rises with larger n, larger true effect, larger α and smaller σ. Only n is under your control after the fact.

How it worksthe written version — read this instead of watching anything

Back to study design, now that you know what inference can and cannot do — plus the calculation that should happen before any study starts.

The centrepiece is the pair of “randoms”, and the exam asks for both with different reasons for each. Random sampling — how cases got into the study — buys generalizability to the population they were drawn from. Random assignment — how cases got into groups — buys causality. They are separate design choices, and a study can have either, both, or neither. Problem 1 walks all four combinations.

Without random assignment you have an observational study and can claim association only, because a confounding variable may be driving both. A confounder must be linked to the explanatory variable and the response — naming one that touches only the response earns nothing. Income is the classic: it predicts both whether someone is insured and whether they can manage their recovery.

The four principles of experimental design are control confounders, randomize subjects into groups, replicate with enough subjects, and block on variables expected to matter. Blocking is grouping similar subjects and randomizing within each block — the design-stage cousin of stratified sampling. Blinding keeps the subject from knowing their group; double-blinding keeps the assessor from knowing too.

Power is 1 − β: the probability of detecting a real effect of a stated size. It rises with a larger sample, a larger true effect, a larger α, and a smaller σ. The practical use is planning: fix the effect worth detecting, the power you want (usually 80%), and α, then solve for n. Problem 2 shows the economics — 91 patients per group to detect 5 mmHg, but only 23 to detect 10, because n scales with 1/d². Do this before collecting data. A trial that fails to reject with 20 patients per group has told you almost nothing.

Look up an idea

  1. Observational vs experimental

    Observation gives association only, because a confounding variable may drive both. Random assignment is what buys causation.

  2. The two 'randoms'

    Random SAMPLING buys generalizability. Random ASSIGNMENT buys causality. Separate design choices — a study can have either, both, or neither.

  3. Confounding variables

    Must be related to BOTH the explanatory and the response variable. Naming one without explaining both links loses the mark.

  4. Four principles of experimental design

    Control, randomize, replicate, block. Blocking is grouping similar subjects and randomizing within each block.

  5. Blinding and placebo

    Blind = the subject does not know. Double-blind = neither the subject nor the assessor knows.

  6. Power

    1 — β: the chance of detecting a real effect of a given size. Rises with larger n, larger true effect, larger α, smaller σ.

  7. Planning a sample size

    Fix the effect worth detecting, the desired power (often 80%) and α, then solve for n. This belongs BEFORE data collection.

08 Oct 26 – Nov 1

Project 1

No lectures, no readings, no quiz. The whole week is the project.

Project checklist

No lectures, no readings, no quiz. This is what a complete write-up contains.

  • State the research question, and say which variable is explanatory and which is the response.
  • Describe the data before analysing it: shape, centre, spread, outliers, and how many cases and variables there are.
  • Choose the procedure and say WHY that one — response type, number of groups, paired or independent.
  • State and check every condition explicitly, in words, before computing.
  • Report the effect size with a confidence interval, not just a p-value.
  • Interpret in context, naming the population and the units, with no statistical jargon left unexplained.
  • Say what the design does and does not license: does it generalize, and is a causal claim supported?
  • Include the software output that supports each claim.
  • Name the limitations honestly — a small n, a convenience sample, a condition that only just holds.
09 Nov 2–8

ANOVA

Three or more group means at once, with a single test at a single α.

Try these first

Have a go before opening the solution. Getting stuck is the point — it tells you which idea below to go and read.

  1. 1
    Complete an ANOVA table and read it
    A study compares mean on-base percentage across four player positions. Partial software output:

    Df Sum Sq Mean Sq F Pr(>F)
    position ? 5.20 ? ? ?
    Residuals 323 110.29 ?


    (a) Fill in every missing value. (b) How many groups, and how many observations? (c) State the conclusion at α = 0.05. (d) How many pairwise comparisons follow, and at what corrected α?

    UsesWhy not many t-testsThe F statisticReading an ANOVA tableMultiple comparisons and BonferroniANOVA conditions

    Work it through
    1. (b) first — the df tell you the design. df for the group row is k − 1, and we are told there are four positions, so df = 3. Residual df is n − k = 323, so n = 323 + 4 = 327 players.
    2. MSG = SSG/df_G = 5.20/3 = 1.7333.
    3. MSE = SSE/df_E = 110.29/323 = 0.3415.
    4. F = MSG/MSE = 1.7333/0.3415 = 5.076.
    5. p = P(F > 5.076) with df 3 and 323 = 0.0019. Upper tail only — large F means the group means are spread out relative to the noise inside the groups.
    6. (c) p = 0.0019 < 0.05, so reject H₀. The data provide strong evidence that at least one position has a different mean on-base percentage. Not that they all differ.
    7. (d) With k = 4 there are K = k(k−1)/2 = 6 pairs. Bonferroni: α* = 0.05/6 = 0.00833. Each pairwise test must clear that bar, not 0.05.

    Answerdf 3 and 323; MSG = 1.7333, MSE = 0.3415, F = 5.076, p = 0.0019. Reject H₀. 6 pairwise comparisons at α* = 0.00833.

    Where this goes wrongIt is entirely possible to reject with ANOVA and then find no significant pair once α* = 0.00833 is applied. That does not invalidate the ANOVA.

  2. 2
    Build an ANOVA from raw data
    Waiting times, in minutes, for five patients at each of three clinics. Test whether mean waiting time differs across clinics at α = 0.05.
    Clinic A:  12  15  11  14  13
    Clinic B:  18  20  17  19  21
    Clinic C:  14  13  16  15  12

    UsesThe F statisticReading an ANOVA tableANOVA conditions

    Work it through
    1. Group means: A = 13.0, B = 19.0, C = 14.0. Grand mean = 15.333.
    2. SSG = Σ ni(x̄i − x̄)² = 103.333, on df_G = k − 1 = 2.
    3. SSE = Σ(x − group mean)² = 30.000, on df_E = n − k = 12.
    4. MSG = 103.333/2 = 51.667; MSE = 30.000/12 = 2.500.
    5. F = 51.667/2.500 = 20.67 on 2 and 12 df, so p = 1.30e-04.
    6. Conditions. Independence — different patients. Normality — groups of 5 are small, so this matters; check for outliers. Constant variance — the three groups spread similarly, and the group sizes are equal, which makes ANOVA forgiving here.
    7. Conclude. Reject H₀. At least one clinic has a different mean waiting time — visibly Clinic B, but the F-test alone does not license naming it.

    AnswerF = 20.67 on 2 and 12 df, p = 1.30e-04. Reject H₀: at least one clinic differs.

    Where this goes wrongWriting “Clinic B is slower” as the ANOVA conclusion. That needs a follow-up pairwise test with a corrected α.

How it worksthe written version — read this instead of watching anything

Three or more group means, with a single test at a single α.

Why not just run every pairwise t-test? Because with k groups there are k(k−1)/2 pairs, and each one gets its own 5% chance of a false positive. With five groups that is ten tests and roughly a 30% chance of at least one spurious “significant” result. ANOVA asks the whole question once.

The idea behind F is a comparison of two kinds of variability. MSG (mean square between groups) measures how far apart the group means are. MSE (mean square error) measures the noise inside the groups. If H₀ is true and all the group means really are equal, both estimate the same underlying variance and F = MSG/MSE lands near 1. A large F means the group means are spread out relative to the noise — evidence against H₀. Only the upper tail is used; there is no such thing as a two-sided F test here.

Reading the table backwards is a standard exam move. The group row has df = k − 1, so k is that plus one. The residual row has df = n − k, so n is that plus k. Mean Sq is always Sum Sq divided by its own df, and F is the ratio of the two Mean Sq values.

Conditions: independence always; normality within each group, which matters most when the groups are small; and constant variance across groups, which matters most when the group sizes are unequal.

Then the discipline at the end. A significant F licenses exactly one sentence: at least one mean differs. It never says which, and never says they all do. To go further, run pairwise comparisons with the Bonferroni correction, α* = α/K where K = k(k−1)/2. And accept the odd-looking outcome: you can reject with ANOVA and then find no single significant pair once the correction applies. That does not invalidate the ANOVA — it means the evidence was spread across the groups rather than concentrated in one contrast.

Look up an idea

  1. Why not many t-tests

    With k groups there are k(k-1)/2 pairs. At α = 0.05 each, the chance of at least one false positive reaches ~30% with 5 groups.

  2. The F statistic

    F = MSG/MSE — between-group variability over within-group variability. If H0 is true both estimate the same variance and F is near 1.

  3. Reading an ANOVA table

    Df for group is k-1, so k = Df+1. Df for residuals is n-k, so n = Df+k. Mean Sq = Sum Sq / Df. Upper tail only.

  4. ANOVA conditions

    Independence always; normality within groups (matters most when groups are small); constant variance across groups (matters most when group sizes differ).

  5. Multiple comparisons and Bonferroni

    A significant F says only that AT LEAST ONE mean differs. Follow up at α* = α/K where K = k(k-1)/2.

10 Nov 9–15

2x2 tables: odds ratios and relative risks

The most distinctly biostatistical week — and the one with NO OpenIntro reading. Everything comes from EBPH.

Try these first

Have a go before opening the solution. Getting stuck is the point — it tells you which idea below to go and read.

  1. 1
    Everything from one 2×2 table
    A cohort study follows 500 adults for five years. Of the 200 who smoke, 45 develop the disease; of the 300 who do not, 30 develop it.

    Compute the risk in each group, the risk difference, the relative risk, the odds ratio, and the number needed to treat. Then interpret the RR and the OR in words.
                  Disease   No disease   Total
    Smoker             45          155     200
    Non-smoker         30          270     300
    Total              75          425     500

    UsesThe 2x2 tableRisk vs oddsRisk difference, relative risk, odds ratioWhen OR approximates RRRelative vs absolute, and NNT

    Work it through
    1. Set the table up with exposure on the rows. Risk is computed across a row.
    2. Risk in smokers: p₁ = 45/200 = 0.225. Risk in non-smokers: p₀ = 30/300 = 0.100.
    3. Risk difference = 0.225 − 0.100 = 0.125, i.e. 12.5 percentage points more.
    4. Relative risk = 0.225/0.100 = 2.250. Smokers were 2.250 times as likely to develop the disease.
    5. Odds ratio = ad/bc = (45×270)/(155×30) = 12150/4650 = 2.613. The cross-product is the fast route.
    6. NNT = 1/|RD| = 1/0.125 = 8.0 → 8. About 8 smokers would have to quit to prevent one case.
    7. Wording, and the verbs matter: “Smokers were 2.25 times as likely to develop the disease as non-smokers” for the RR; “the odds of disease were 2.61 times higher among smokers” for the OR.
    8. Notice OR (2.61) > RR (2.25). The outcome here is 22.5% in the exposed group — not rare — so the odds ratio overstates the risk ratio.

    Answerp₁ = 0.225, p₀ = 0.100, RD = 0.125, RR = 2.250, OR = 2.613, NNT = 8.

    Where this goes wrongReporting the OR of 2.61 as “2.61 times as likely”. That is the RR's phrasing, and the RR is only 2.25.

  2. 2
    Confidence intervals through the log
    Using the same table, build 95% confidence intervals for the relative risk and the odds ratio. Then say whether the association is statistically significant, and how you can tell at a glance that the arithmetic was done correctly.
    a = 45   b = 155   c = 30   d = 270

    UsesConfidence intervals go through the logRisk difference, relative risk, odds ratio

    Work it through
    1. RR and OR are bounded below by 0 and unbounded above, so their sampling distributions are right-skewed. A symmetric ± interval would be wrong. Work on the log scale, then transform back.
    2. RR. ln(RR) = ln(2.250) = 0.8109. SE(ln RR) = √(1/a − 1/(a+b) + 1/c − 1/(c+d)) = 0.2173.
    3. On the log scale: 0.8109 ± 1.96×0.2173 = (0.3850, 1.2368). Exponentiate: (1.470, 3.445).
    4. OR. SE(ln OR) = √(1/45 + 1/155 + 1/30 + 1/270) = 0.2563 — just the reciprocals of the four cells, which is why it is the easier one to remember.
    5. ln(OR) = 0.9605, so the interval is exp(0.9605 ± 1.96×0.2563) = (1.581, 4.318).
    6. Both intervals exclude 1, so the association is statistically significant at the 5% level. Remember: ratios are compared against 1, not 0.
    7. The check: the RR interval runs 0.780 below the estimate and 1.195 above it. The asymmetry is the signature of a correctly log-transformed interval. If yours came out symmetric, you skipped the log.

    AnswerRR = 2.250, 95% CI (1.470, 3.445). OR = 2.613, 95% CI (1.581, 4.318). Both exclude 1 — a significant association.

    Where this goes wrongBuilding 2.25 ± 1.96×SE directly on the ratio scale. It gives a symmetric interval that can even dip below zero, which is impossible for a ratio.

  3. 3
    Which measure is even legal here?
    A case–control study recruits 200 patients with pancreatic cancer and 200 healthy controls, then asks each about past pesticide exposure. 90 of the cases and 60 of the controls report exposure.

    (a) Can you compute the risk of cancer among the exposed? (b) Can you compute a relative risk? (c) Compute whatever measure IS legitimate. (d) Explain the reason in one sentence.
                  Cancer   Control   Total
    Exposed           90        60     150
    Not exposed      110       140     250
    Total            200       200     400

    UsesStudy design decides which measure you can useRisk difference, relative risk, odds ratio

    Work it through
    1. (a) No. You could compute 90/150 = 0.450, but that number is meaningless — the researchers chose to recruit 200 cases and 200 controls. Change that ratio to 1:4 and the number moves, even though nothing about the world changed.
    2. (b) No. A relative risk is a ratio of two risks, and neither risk is estimable, so the RR is not either.
    3. (c) The odds ratio is legitimate: OR = ad/bc = (90×140)/(60×110) = 12600/6600 = 1.909.
    4. (d) The reason: in a case–control study subjects are selected on the outcome, which fixes the column totals. The cross-product ad/bc is unchanged whether you sample on rows or on columns — that symmetry is the entire reason the odds ratio exists and why it dominates epidemiology.
    5. Interpretation: “The odds of pesticide exposure were 1.91 times higher among pancreatic cancer cases than among controls.” Because the disease is rare in the population, this OR also approximates the relative risk you could not measure directly.

    AnswerOnly the odds ratio: OR = 1.909. Risk and relative risk are not estimable because subjects were selected on the outcome.

    Where this goes wrongThis is week 10's signature exam question. If a study description says how many CASES and how many CONTROLS were recruited, risk is off the table.

How it worksthe written version — read this instead of watching anything

The most distinctly biostatistical week, and the one with no OpenIntro reading at all. These are the measures epidemiology and clinical research actually report.

Everything comes out of one 2×2 table, so set it up the same way every time: exposure on the rows, outcome on the columns. Risk is computed across a row, which is why the orientation has to be right before anything else happens.

Risk is not odds. Risk is cases divided by everyone; odds is cases divided by non-cases. A risk of 0.5 is odds of 1; a risk of 0.8 is odds of 4. The three comparison measures follow: the risk difference (p₁ − p₀, an absolute measure, null value 0), the relative risk (p₁/p₀, null value 1), and the odds ratio (ad/bc by the cross-product, null value 1). Comparing a ratio against 0 is a guaranteed wrong answer.

Confidence intervals for RR and OR must go through the log. Both are bounded below by 0 and unbounded above, so their sampling distributions are right-skewed and a symmetric ± interval would be wrong — it can even dip below zero, which is impossible for a ratio. Take ln, build a symmetric interval there, exponentiate the endpoints. The result comes out asymmetric around the estimate, and that asymmetry is your check that you did it right.

The conceptual heart is that study design decides which measure you can even use. In a cohort study or a trial, subjects are grouped by exposure and followed, so risk is observable and RD, RR and OR are all available. In a case–control study, subjects are recruited by outcome — the researcher chooses how many cases and how many controls — so the row totals are an artifact of recruitment and risk is not estimable. The odds ratio survives because ad/bc is unchanged whether you sample on rows or columns. That symmetry is the entire reason the odds ratio exists.

Finally: OR ≈ RR only when the outcome is rare, under roughly 10%. When it is common the OR is always further from 1, and reporting it as a risk ratio overstates the effect — a real and common error in published papers.

Look up an idea

  1. The 2x2 table

    Exposure on the rows, outcome on the columns. Risk is computed ACROSS a row — so getting the orientation right comes before everything else.

  2. Risk vs odds

    Risk is cases over EVERYONE; odds is cases over NON-cases. A risk of 0.5 is odds of 1; a risk of 0.8 is odds of 4.

  3. Risk difference, relative risk, odds ratio

    RD = p1 — p0 (null 0). RR = p1/p0 (null 1). OR = ad/bc (null 1). The cross-product is the fastest way to the OR.

  4. Confidence intervals go through the log

    RR and OR are right-skewed, so take ln, build a symmetric interval, then exponentiate. The result is ASYMMETRIC around the estimate — that is the check you did it right.

  5. Study design decides which measure you can use

    A case-control study selects on the OUTCOME, so the row totals are an artifact of recruitment and risk is not estimable. Only the OR survives. This is the week's signature exam question.

  6. When OR approximates RR

    Only when the outcome is rare (under ~10%). When it is common the OR is always further from 1 — reporting it as a risk ratio overstates the effect.

  7. Relative vs absolute, and NNT

    NNT = 1/|RD|. A halving of risk from 2 to 1 per 100,000 is RR = 0.5 and NNT = 100,000. Both numbers are true; reporting only the relative one is how press releases mislead.

11 Nov 16–22

Hypothesis testing for two or more categories

The tests that go with week 10's measures. Same 2x2 tables, now asking whether the association is distinguishable from chance.

Try these first

Have a go before opening the solution. Getting stuck is the point — it tells you which idea below to go and read.

  1. 1
    Chi-square goodness of fit
    A clinic records missed appointments by weekday over one quarter: Monday 42, Tuesday 31, Wednesday 18, Thursday 29. The manager claims missed appointments are spread evenly across the four days. Test that claim at α = 0.05.
    Day        Mon   Tue   Wed   Thu   Total
    Observed    42    31    18    29     120

    UsesChi-square goodness of fitConditionsUpper tail only

    Work it through
    1. Hypotheses. H₀: missed appointments are evenly spread (each day has probability 1/4). Hₐ: they are not evenly spread.
    2. Expected counts under H₀: 120/4 = 30 for each day. All are ≥ 5, and each missed appointment falls in exactly one cell, so both conditions hold.
    3. X² = Σ(O − E)²/E = (42−30)²/30 + (31−30)²/30 + (18−30)²/30 + (29−30)²/30 = 9.667.
    4. df = k − 1 = 4 − 1 = 3. Note it is the number of categories minus one, NOT n − 1.
    5. p = P(X² > 9.667) with 3 df = 0.0216. Upper tail only — a large X² means the observed counts sit far from what H₀ predicts.
    6. Conclude. p = 0.0216 < 0.05, so reject H₀. The data provide strong evidence that missed appointments are not evenly spread across the week. Looking at the cells, Wednesday (18 vs 30 expected) is the main driver.

    AnswerX² = 9.667 on 3 df, p = 0.0216. Reject H₀ — the days are not equally likely.

    Where this goes wrongThe critical value here is 7.815. Doubling the p-value to make it “two-sided” is wrong — chi-square is already the whole test.

  2. 2
    Chi-square for a two-way table
    Is insurance type associated with attending a follow-up appointment? Test at α = 0.05.
                  Attended   Missed   Total
    None                38       62     100
    Public              51       49     100
    Private             72       28     100
    Total              161      139     300

    UsesChi-square test of independenceConditionsUpper tail only

    Work it through
    1. Hypotheses. H₀: insurance type and attendance are independent. Hₐ: they are associated.
    2. Expected counts: E = (row total × column total)/table total. For None/Attended: (100×161)/300 = 53.667.
    3. Full expected table: None = (53.67, 46.33); Public = (53.67, 46.33); Private = (53.67, 46.33). All are comfortably ≥ 5.
    4. X² = Σ(O − E)²/E over all six cells = 23.674.
    5. df = (R − 1)(C − 1) = (3−1)(2−1) = 2.
    6. p = 7.23e-06, far below 0.05, so reject H₀.
    7. Conclude. The data provide strong evidence that insurance type and follow-up attendance are associated. Comparing O with E cell by cell shows privately insured patients attended more often than independence predicts (72 vs 53.7) and uninsured patients less often (38 vs 53.7).

    AnswerX² = 23.674 on 2 df, p = 7.23e-06. Reject H₀ — insurance type and attendance are associated.

    Where this goes wrongChi-square says an association EXISTS. It does not say which group differs or in which direction — for that, compare O with E cell by cell.

  3. 3
    Two proportions: pooled or not?
    Back to week 10's cohort: 45 of 200 smokers and 30 of 300 non-smokers developed the disease.

    (a) Test H₀: p₁ = p₀ at α = 0.05. (b) Build a 95% confidence interval for p₁ − p₀. (c) Explain why the two use different standard errors.

    UsesTwo proportions2x2: z-test and chi-square agreeA test uses p0, a CI uses p̂

    Work it through
    1. p̂₁ = 45/200 = 0.225, p̂₀ = 30/300 = 0.100.
    2. (a) The null says the two proportions are equal, so pool them to estimate that one shared value: p̂pool = (45+30)/(200+300) = 0.150.
    3. SEtest = √(p̂pool(1−p̂pool)(1/n₁ + 1/n₀)) = 0.03260.
    4. Z = (0.225 − 0.100)/0.03260 = 3.835, two-sided p = 0.0001 → reject H₀.
    5. (b) A confidence interval makes no such supposition, so each group gets its own estimate: SECI = √(p̂₁(1−p̂₁)/n₁ + p̂₀(1−p̂₀)/n₀) = 0.03423.
    6. Interval: (0.225 − 0.100) ± 1.96×0.03423 = (0.0579, 0.1921). It excludes 0, agreeing with the test.
    7. (c) A test supposes H₀ is true, and H₀ says the proportions are equal — so the best estimate of that common value uses all 500 people. A confidence interval assumes nothing, so it estimates each group separately.
    8. Cross-check: Z² = 3.835² = 14.706, which is exactly the X² you would get from the chi-square test on this same 2×2 table.

    Answer(a) Z = 3.835, p = 0.0001 — reject H₀. (b) 95% CI (0.0579, 0.1921). (c) The test pools because H₀ says the proportions are equal; the interval does not.

    Where this goes wrongUsing the unpooled SE for the test, or the pooled one for the interval. Both are real errors, not rounding.

How it worksthe written version — read this instead of watching anything

Week 10 measured how strong an association is. This week tests whether it is distinguishable from chance. Same 2×2 tables, different question — and a complete answer reports both.

Two proportions. The standard error depends on what you are doing, and this is the chapter's main trap. A confidence interval estimates each group separately: SE = √(p̂₁(1−p̂₁)/n₁ + p̂₂(1−p̂₂)/n₂). A test of H₀: p₁ = p₂ supposes the two proportions are the same, so it pools all the data to estimate that one shared value and uses SE = √(p̂pool(1−p̂pool)(1/n₁ + 1/n₂)). Same logic as p₀ versus p̂ in week 5: a test uses what the null implies.

Chi-square handles counts. The statistic is always X² = Σ(O − E)²/E summed over every cell, using counts, never proportions. What changes between the two versions is where E comes from and what df is.

For a goodness of fit test — one variable, k categories — E comes from the claimed distribution (often n/k if H₀ says all categories are equally likely) and df = k − 1. For a test of independence — two variables in a two-way table — E = (row total × column total)/table total, which is just the independence rule P(A and B) = P(A)P(B) rewritten in counts, and df = (R−1)(C−1).

Only the upper tail is used, because X² measures total squared deviation from expectation and large values mean poor fit. Do not double the p-value to make it “two-sided” — it is already the whole test. Conditions: independence, and every expected count at least 5 — the expected count, not the observed one.

On a 2×2 table the z-test and chi-square agree exactly: z² = X², and the p-values match. Problem 3 checks this numerically. Use whichever the question asks for; the z-test additionally gives a confidence interval for the difference, which chi-square cannot.

Look up an idea

  1. Two proportions

    CI uses each group's own p̂. The TEST of p1 = p2 uses the POOLED proportion, because the null says they are the same.

  2. Chi-square goodness of fit

    One variable, k categories. X² = sum (O-E)²/E, df = k-1. Counts, never proportions.

  3. Chi-square test of independence

    Two variables in a table. E = (row total x column total)/table total, df = (R-1)(C-1).

  4. Conditions

    Independence, and every EXPECTED count at least 5. A cell with 1 observed but 9 expected is fine. If one falls short, combine categories.

  5. Upper tail only

    X² measures total squared deviation from expectation, so large values mean poor fit. There is no two-sided chi-square test — do not double the p-value.

  6. 2x2: z-test and chi-square agree

    For a 2x2 table, z² = X² and the p-values match. The z-test additionally gives a confidence interval for the difference.

12 Nov 23–29

Correlation & simple linear regression

Two numerical variables. Fitting and describing only — inference waits for week 13.

Try these first

Have a go before opening the solution. Getting stuck is the point — it tells you which idea below to go and read.

  1. 1
    Fit a line from summary statistics
    For 50 patients, x = age (years) and y = a lung-function score.
    x̄ = 48.0, sx = 12.4, ȳ = 22.5, sy = 3.8, R = −0.62.

    (a) Find the least squares line. (b) Predict the score for a 60-year-old. (c) A 60-year-old actually scores 19.0 — find the residual. (d) Interpret the slope and R². (e) Would you use this to predict the score of a 5-year-old?

    UsesLeast squaresThe model and residualsCorrelation RInterpreting slope and interceptR-squaredExtrapolation

    Work it through
    1. (a) Slope: b₁ = (sy/sx)R = (3.8/12.4)×(−0.62) = -0.1900.
    2. The line always passes through (x̄, ȳ), so b₀ = ȳ − b₁x̄ = 22.5 − (-0.1900)×48.0 = 31.620.
    3. Line: ŷ = 31.62 + (-0.1900)x, or ŷ = 31.62 − 0.1900x.
    4. (b) At x = 60: ŷ = 31.62 − 0.1900×60 = 20.220.
    5. (c) Residual = observed − predicted = 19.0 − 20.220 = -1.220. Negative, so this patient scored below what the model predicted.
    6. (d) Slope: “For each additional year of age, the model predicts a lung-function score 0.190 points lower, on average.” A difference between patients, not a change within one patient — and not causal, since this is observational data.
    7. R² = (-0.62)² = 0.3844: about 38% of the variability in lung-function score is explained by the linear model using age.
    8. (e) No. The data cover adults around age 48; age 5 is far outside that range. That is extrapolation, and the model provides no evidence the line continues out there. The intercept 31.62 is the predicted score at age 0, which is equally meaningless.

    Answerŷ = 31.62 − 0.1900x. Predicted 20.22 at age 60; residual -1.22. R² = 0.384, so 38% of variability explained. No prediction at age 5.

    Where this goes wrongR² = 0.384 does NOT mean 38% of the points sit on the line. It is the share of the variability in y the model explains.

  2. 2
    Diagnose four residual plots
    Each residual plot below shows a different problem. Name the condition each one violates and say what you would do.

    (a) The residuals form a clear U-shape.
    (b) The residuals fan out — narrow on the left, wide on the right.
    (c) The residuals drift steadily upward when plotted in the order the data were collected.
    (d) The residuals look like a structureless band, but one point sits far to the right of all others and the line tilts noticeably when it is removed.

    UsesReading a residual plotThe LINE conditionsOutlier, leverage, influence

    Work it through
    1. (a) Linearity fails. A U-shape means the true relationship is curved and a straight line is the wrong model. Fix: transform x or y (log, square root), or add a quadratic term.
    2. (b) Constant variance fails. The spread of the residuals grows with the fitted value, so the model is far more precise at one end than the other. Fix: transform the response, often with a log.
    3. (c) Independence fails. Residuals that trend with collection order mean something changed over time — equipment drift, a seasonal effect, a learning curve. This is the condition a scatterplot of y against x will never show you.
    4. (d) Not a condition failure at all — this is an influential point. It sits far out in x, so it has high leverage, and removing it visibly moves the line, which is what makes it influential.
    5. For (d): do not delete it. Report the fit with and without the point and say what changed. Leverage is the opportunity to move the line; influence is the effect.

    Answer(a) linearity — transform. (b) constant variance — transform y. (c) independence — time-ordered structure. (d) an influential high-leverage point, not a condition failure.

    Where this goes wrongA point extreme in y but sitting at the middle of the x range has almost no leverage and barely tilts the line. Leverage is about x.

How it worksthe written version — read this instead of watching anything

Two numerical variables. This week fits and describes the line; inference about it waits for week 13.

The model is ŷ = b₀ + b₁x, and the residual of any point is e = y − ŷ — observed minus predicted. A positive residual means the point sits above the line and the model under-predicted.

The residual plot is the diagnostic that matters, because it magnifies what a scatterplot hides. A good fit shows a structureless horizontal band. Curvature means the relationship is not linear. Fanning — narrow at one end, wide at the other — means non-constant variance. A drift when plotted in collection order means the residuals are not independent, and that is the problem a plot of y against x will never reveal.

Correlation R measures the strength and direction of a linear relationship and runs from −1 to 1. Describe it with three words: strength, direction, and linear. R near 0 means no linear relationship — a perfect U-shape has R ≈ 0 while being perfectly predictable, so always look at the scatterplot.

Least squares picks the line minimising the sum of squared residuals, which is why one extreme point can dominate the fit. From summary statistics, b₁ = (sy/sx)R, and because the line always passes through (x̄, ȳ) you get b₀ = ȳ − b₁x̄. Remember that one fact and you never need to memorise the intercept formula.

Interpreting the slope has a required shape: “for each additional one unit of x, we expect y to be b₁ higher, on average.” Say “on average”, and frame it as a difference between cases — not a change within one case, and not causal unless the data came from a randomized experiment. The intercept is the mean y at x = 0, which is usually meaningless because x = 0 sits outside the data; say so when it does. Predicting outside the observed range of x is extrapolation and the model gives no evidence for it.

is the share of the variability in y the model explains. R keeps the direction, R² keeps only the strength — and R² = 0.38 does not mean 38% of the points sit on the line.

Look up an idea

  1. The model and residuals

    ŷ = b0 + b1x, and e = y — ŷ. A positive residual means the point sits above the line and the model under-predicted.

  2. Reading a residual plot

    A good fit is a structureless horizontal band. Curvature means not linear; fanning means non-constant variance.

  3. Correlation R

    Strength and direction of a LINEAR relationship, between -1 and 1. A perfect U-shape has R near 0 while being perfectly predictable — always look at the scatterplot.

  4. Least squares

    b1 = (sy/sx)R and b0 = y-bar — b1*x̄. The line always passes through (x̄, y-bar) — remember that and you can rebuild b0.

  5. Interpreting slope and intercept

    The slope is a difference between cases whose x differs by one, 'on average' — not a change within one case. The intercept is meaningless when x = 0 is outside the data.

  6. R-squared

    The share of variability in y the model explains. R keeps the direction, R² keeps only the strength.

  7. Extrapolation

    Predicting outside the observed range of x is not supported by the model. The data say nothing about what happens out there.

13 Nov 30 – Dec 6

Inference for simple linear regression

Is the slope real? Plus the conditions and the outlier vocabulary.

Try these first

Have a go before opening the solution. Getting stuck is the point — it tells you which idea below to go and read.

  1. 1
    Read regression output and test the slope
    Software output for gift aid regressed on family income:

    Estimate Std. Error t value Pr(>|t|)
    (Intercept) 24319.33 1291.45 18.83 <2e-16
    family_income -0.0431 0.0108 ? ?

    Residual standard error: 4783 on 48 degrees of freedom
    Multiple R-squared: 0.2485


    (a) How many students were in the sample? (b) Fill in the t value and p-value for the slope. (c) Build a 95% confidence interval for the slope. (d) State the conclusion and interpret the slope. (e) What is the correlation R?

    UsesReading regression outputTesting the slopeConfidence interval for a coefficientThe LINE conditionsR-squared

    Work it through
    1. (a) For simple linear regression df = n − 2, because two parameters were estimated. So n = 48 + 2 = 50.
    2. (b) t = Estimate/Std. Error = -0.0431/0.0108 = -3.991.
    3. The two-sided p-value with 48 df is 0.00022 — this tests H₀: β₁ = 0, no linear relationship.
    4. (c) t* for 95% with 48 df is 2.0106, so the interval is -0.0431 ± 2.0106×0.0108 = (-0.06481, -0.02139).
    5. (d) p = 0.00022 < 0.05, so reject H₀. There is strong evidence of a negative linear relationship. Interpretation: “For each additional $1,000 of family income, the model predicts about $43.10 less gift aid, on average.” (The slope is per dollar; multiply by 1,000.)
    6. Note the interval excludes 0, which agrees with the test — as it always will for a two-sided test at the matching level.
    7. (e) R² = 0.2485, so |R| = √0.2485 = 0.498. The slope is negative, so R = −0.498. R² alone cannot give you the sign.

    Answer(a) n = 50. (b) t = -3.991, p = 0.00022. (c) (-0.06481, -0.02139). (d) Reject H₀; about $43.10 less aid per extra $1,000 of income. (e) R = −0.498.

    Where this goes wrongUsing df = n − 1 = 49 instead of n − 2 = 48. It gives a plausible p-value that is quietly wrong.

  2. 2
    Outlier, leverage, or influence?
    A scatterplot of 40 points runs from x = 10 to x = 30. Classify each additional point as an outlier, high leverage, influential, more than one, or none — and say what you would report.

    (a) A point at x = 20 (mid-range) that sits far above the line.
    (b) A point at x = 75, close to where the extended line would pass.
    (c) A point at x = 75 that sits far off the extended line; removing it changes the slope from 0.8 to 0.3.
    (d) A point at x = 12 sitting right on the line.

    UsesOutlier, leverage, influence

    Work it through
    1. (a) Outlier, but low leverage. It is far from the cloud vertically, yet sits in the middle of the x range, so it barely tilts the line — it mostly just shifts it slightly and inflates the residual spread.
    2. (b) High leverage, not an outlier, not influential. Being far out in x gives it the power to move the line, but it agrees with the trend so it does not use that power.
    3. (c) High leverage AND influential (and an outlier relative to the fit). Far out in x, far off the line, and removing it more than halves the slope. This is the dangerous one.
    4. (d) None of the three. It is a perfectly ordinary point.
    5. The reporting rule for (c): never delete it just because it is inconvenient. Fit the model with and without it, report both slopes, and explain what the point is. If it is a data-entry error, fix it; if it is a real case, it is telling you something.

    Answer(a) outlier, low leverage. (b) high leverage only. (c) high leverage and influential. (d) none.

    Where this goes wrongLeverage is about x alone and can be judged before the line is even fitted. Influence needs the fit, and only shows up when you remove the point.

How it worksthe written version — read this instead of watching anything

Now: is the slope real, and which points are driving it?

The four conditions are worth a mnemonic, LINE: Linearity, Independent residuals, Nearly normal residuals, Equal variance. All four are judged on the residuals, not on the original scatterplot.

Three words get confused constantly and the exam tests the distinction. An outlier is far from the cloud of points. High leverage means far from the centre horizontally — extreme in x, and judgeable before the line is even fitted. An influential point is a high-leverage point that visibly moves the line when removed. Leverage is the opportunity to move the line; influence is the effect. A point extreme in y but sitting in the middle of the x range has almost no leverage and barely tilts anything.

The rule for handling one: never delete a point because it is inconvenient. Report the fit with and without it and say what changed.

Inference on the slope tests H₀: β₁ = 0, meaning no linear relationship. The statistic is t = b₁/SEb₁ with df = n − 2 — two parameters were estimated, b₀ and b₁, so you lose two. Using n − 1 gives a plausible-looking p-value that is quietly wrong.

Reading software output is most of the practical skill. The Estimate column gives b₀ and b₁; the t value is simply Estimate divided by Std. Error; Pr(>|t|) is the two-sided p-value for that coefficient. The line “Residual standard error: 4783 on 48 degrees of freedom” tells you n = 50, which is a favourite exam question. A confidence interval for the slope is b₁ ± t*df×SE, and it will exclude 0 exactly when the two-sided test rejects.

One last connection: testing the slope against 0 is the same test as asking whether the correlation is 0 — identical p-value. And |R| = √R², with the sign taken from the slope, since R² alone cannot tell you the direction.

Look up an idea

  1. The LINE conditions

    Linearity, Independent residuals, Nearly normal residuals, Equal variance. All four are checked on the residuals.

  2. Outlier, leverage, influence

    Three different things. High leverage is extreme in x. An influential point is a high-leverage point that MOVES the line when removed. Leverage is the opportunity; influence is the effect.

  3. Testing the slope

    H0: beta1 = 0 means no linear relationship. t = b1/SE_b1 with df = n — 2 — two parameters were estimated.

  4. Reading regression output

    Estimate / Std. Error = t value. 'Residual standard error on 48 degrees of freedom' means n = 50. Testing the slope against 0 is the same test as testing whether the correlation is 0.

  5. Confidence interval for a coefficient

    b1 ± t*_df x SE_b1, with df = n — 2.

14 Dec 7–13

Multiple linear regression

Several predictors at once. The last content week — and notably NOT logistic regression.

Try these first

Have a go before opening the solution. Getting stuck is the point — it tells you which idea below to go and read.

  1. 1
    Interpret a multiple regression
    Length of hospital stay (nights) is modelled on age (years), a severity score (1–10), and insurance type (None / Public / Private).

    Estimate Std. Error t Pr(>|t|)
    (Intercept) 1.204 0.612 1.97 0.049
    age 0.031 0.008 3.88 <0.001
    severity 0.842 0.061 13.80 <0.001
    insurancePublic -0.415 0.190 -2.18 0.030
    insurancePrivate -0.902 0.203 -4.44 <0.001


    (a) Interpret the age coefficient. (b) Which insurance level is the reference, and how do you know? (c) Interpret the insurancePrivate coefficient. (d) How many predictors k does this model have? (e) In simple regression age had a coefficient of 0.089. Why did it shrink?

    Uses'Holding all else constant'Categorical predictors and the reference levelWhy a coefficient can flip signThe multiple regression model

    Work it through
    1. (a) “Among patients with the same severity score and the same insurance type, each additional year of age is associated with a stay 0.031 nights longer, on average.” The holding all else constant clause is the whole point of multiple regression and must appear.
    2. (b) None is the reference. A three-level predictor gets k − 1 = 2 coefficients, and the level with no row is the one left out. Public and Private are each measured against None.
    3. (c) “Privately insured patients stay 0.902 nights fewer than uninsured patients with the same age and severity, on average.” The comparison is against the reference level, never in absolute terms.
    4. (d) age (1) + severity (1) + insurance (3 levels → 2) = k = 4. A categorical predictor with p levels contributes p − 1, which matters for adjusted R² and for df = n − k − 1.
    5. (e) In simple regression the age coefficient absorbed everything correlated with age that was left out of the model — chiefly severity, since older patients tend to be sicker. Once severity is in the model, age is adjusted for it and its coefficient drops to its own contribution. That is expected behaviour, not a bug.

    Answer(a) +0.031 nights per year, holding severity and insurance fixed. (b) None — it has no coefficient. (c) 0.902 nights fewer than uninsured, all else equal. (d) k = 4. (e) The simple model's coefficient was confounded with severity.

    Where this goes wrongDropping “holding all other variables constant”. Without it the sentence describes a different (simple-regression) quantity.

  2. 2
    Choose between models
    Four nested models fitted to the same n = 120 patients. Compute the adjusted R² for each and say which model you would report, and why plain R² cannot answer this.
    Model                                  k    R-squared
    age                                    1      0.214
    age + severity                         2      0.601
    age + severity + insurance             4      0.629
    age + severity + insurance + weekday   5      0.630

    UsesAdjusted R-squaredThe multiple regression modelCategorical predictors and the reference levelCollinearityDiagnostic plots

    Work it through
    1. adj = 1 − (1 − R²) × (n − 1)/(n − k − 1), with n = 120.
    2. age: k = 1, R² = 0.214, R²adj = 0.2073
    3. age + severity: k = 2, R² = 0.601, R²adj = 0.5942
    4. age + severity + insurance: k = 4, R² = 0.629, R²adj = 0.6161
    5. age + severity + insurance + weekday: k = 5, R² = 0.630, R²adj = 0.6138
    6. Plain R² rises every single time — 0.214 → 0.601 → 0.629 → 0.630 — because it never decreases when a predictor is added, even a worthless one. So it cannot compare models of different sizes.
    7. Adjusted R² peaks at the age + severity + insurance model (0.6161) and then falls when weekday is added (0.6138). Weekday earned less than it cost.
    8. Report age + severity + insurance. Note that insurance counts as 2 towards k, not 1 — a three-level categorical predictor contributes p − 1.

    AnswerAdjusted R²: 0.2073, 0.5942, 0.6161, 0.6138. Report age + severity + insurance — adding weekday lowers adjusted R².

    Where this goes wrongChasing the highest plain R² always selects the biggest model. That is overfitting with extra steps.

How it worksthe written version — read this instead of watching anything

Several predictors at once. Note what is not here: model selection strategies and logistic regression are both excluded from this course.

The model is ŷ = b₀ + b₁x₁ + … + bkxk, with df = n − k − 1.

The interpretation of a coefficient changes in a way that is the entire point of the technique: each one is the estimated difference in y per one-unit larger xi, holding all the other predictors constant. That clause is not decoration — drop it and you are describing a different quantity. Every interpretation you write this week must contain it.

A direct consequence: a coefficient can shrink, grow, or flip sign when other predictors are added. That is expected, not a bug. A simple regression coefficient silently absorbs the effect of everything correlated with it that was left out; the multiple regression coefficient has been adjusted for those variables. Problem 1 shows age dropping from 0.089 to 0.031 once severity enters, because older patients tend to be sicker and the simple model was crediting age with severity's effect.

Categorical predictors with p levels get p − 1 coefficients. The level with no coefficient is the reference level, and every other coefficient is measured against it — never in absolute terms. This also matters for counting: a three-level predictor contributes 2 to k, which changes both the degrees of freedom and the adjusted R².

Plain R² never decreases when you add a predictor, even a worthless one, so it cannot compare models of different sizes — chasing it always selects the biggest model. Adjusted R² penalises the number of predictors and can go down, which is exactly what makes it useful: the model where it peaks is the one to report.

Diagnostics are the same LINE conditions read off four plots: residuals versus fitted values (linearity, equal variance), a normal probability plot of the residuals (normality), residuals versus each predictor (curvature the overall plot missed), and residuals in collection order (independence). Watch for collinearity too — two predictors carrying nearly the same information make each other's coefficients unstable, so neither looks significant even though together they matter.

Look up an idea

  1. The multiple regression model

    ŷ = b0 + b1x1 + ... + bkxk, with df = n — k — 1.

  2. 'Holding all else constant'

    Each coefficient is the difference in y per one-unit larger xi with the other predictors fixed. That qualifier is the whole point, and must appear in the interpretation.

  3. Why a coefficient can flip sign

    A simple-regression coefficient absorbs the effect of omitted variables; the multiple-regression one is adjusted for them. Expected, and often the point.

  4. Categorical predictors and the reference level

    A predictor with p levels gets p-1 coefficients, all measured against the level left out. It also contributes p-1 to k.

  5. Adjusted R-squared

    Plain R² never decreases when you add a predictor, so it cannot compare models of different sizes. Adjusted R² penalises the count and CAN go down.

  6. Diagnostic plots

    Residuals vs fitted (linearity, equal variance), normal probability plot (normality), residuals vs each predictor (missed curvature), residuals vs collection order (independence).

  7. Collinearity

    Two predictors carrying the same information make each other's coefficients unstable, so neither looks significant even though together they matter.

15 Dec 14–20

Project 2

No lectures, no readings, no quiz. The term ends with the second project.

Project checklist

No lectures, no readings, no quiz. This is what a complete write-up contains.

  • State the research question, and say which variable is explanatory and which is the response.
  • Describe the data before analysing it: shape, centre, spread, outliers, and how many cases and variables there are.
  • Choose the procedure and say WHY that one — response type, number of groups, paired or independent.
  • State and check every condition explicitly, in words, before computing.
  • Report the effect size with a confidence interval, not just a p-value.
  • Interpret in context, naming the population and the units, with no statistical jargon left unexplained.
  • Say what the design does and does not license: does it generalize, and is a causal claim supported?
  • Include the software output that supports each claim.
  • Name the limitations honestly — a small n, a convenience sample, a condition that only just holds.

No week matches that. Press Escape to clear the filter.

Concept library

Every idea, explained

The same entries the Uses chips open, laid out to browse. Each one is a short explanation, a worked example, then longer text if you want it — and a video only as a last resort.

Week 1Introduction & data summaries

Cases, variables, and the data matrix

A data matrix is the standard rectangular layout: each row is a case (one patient, one hospital, one appointment) and each column is a variable measured on every case. n is the number of rows. Fixing this early prevents degrees-of-freedom errors later, because n is what every df formula counts.

Example
A school health screening records, for each of 1,150 pupils, their year group, height, vision test result and whether they wear glasses. That is a matrix with 1,150 rows and 4 columns, so n = 1,150 — not 4, and not 4,600.

Variable types

Every variable is numerical (arithmetic on the values means something) or categorical (it takes one of a set of labels). Numerical splits into discrete (counts, separated values) and continuous (any value in a range). Categorical splits into nominal (no order) and ordinal (a natural order). The test is never how the value looks — it is whether arithmetic on it means anything.

Example
Birth weight in grams → numerical, continuous. Number of siblings → numerical, discrete. Blood type (A/B/AB/O) → categorical, nominal. Triage category 1–5 → categorical, ordinal — the numbers rank urgency, but category 4 is not twice category 2, so averaging them is meaningless.
Longer explanations

Describing a distribution

Four things, every time: shape (symmetric or skewed; one peak or several), centre, spread, and unusual observations. Leaving any one out loses marks even when the arithmetic is right. Skew is named for the tail, not for where the bulk of the data sits.

Example
“Ambulance response times are strongly right-skewed and unimodal (shape), centred on a median of 7 minutes (centre), with an IQR of 4 minutes (spread), and one response at 34 minutes far above the rest (unusual observations).” Waiting times are almost always right-skewed: a hard floor at zero, no ceiling.

Mean/SD vs median/IQR

Match the summary to the shape. For roughly symmetric data with no outliers, use the mean and standard deviation — they use every value. When the data are skewed or contain outliers, use the median and IQR, the robust pair, which barely move when one extreme value is added. In a right-skewed distribution the mean is pulled above the median.

Example
Eleven ambulance response times, in minutes: 4, 5, 5, 6, 6, 7, 7, 8, 9, 11, 34. Mean = 9.27, median = 7.0. Remove the 34 and the mean collapses to 6.80 while the median barely moves, to 6.5. One value dragged the mean by nearly 2.5 minutes and the median by half of one — so report the median and IQR here.

Box plots and the 1.5xIQR rule

The box spans Q1 to Q3 with the median marked inside, so the box itself is the IQR. Whiskers reach the furthest observation within 1.5×IQR of the box; anything beyond is drawn individually as a suspected outlier. Flagged, not deleted — an outlier is a prompt to investigate.

Example
For those response times, Q1 = 5 and Q3 = 9, so IQR = 4 and 1.5×IQR = 6. The fences sit at 5 − 6 = −1 and 9 + 6 = 15. The 34-minute response is well past the upper fence and gets plotted as a point; an 11-minute response sits inside it and stays under the whisker.

Contingency tables, row vs column proportions

A contingency table cross-tabulates counts for two categorical variables, with row and column totals in the margins. A row proportion divides a cell by its row total; a column proportion divides by the column total. They answer different questions, and the question tells you which by naming what is held fixed.

Example
250 cyclists wore a helmet and 250 did not; 30 of the helmeted and 60 of the unhelmeted arrived with a head injury (90 injuries in all).
“Among helmet wearers, what share were injured?” fixes the row: 30/250 = 12%.
“Among the injured, what share wore a helmet?” fixes the column: 30/90 = 33%. Same 30, two different denominators, two different questions.
Longer explanations

Simulation-based inference (the case study)

Before any formulas, you can answer “could chance alone produce a difference this big?” by shuffling. Randomly reassign the group labels many times, recompute the difference each time, and see how often shuffling alone produces something as extreme as what you actually observed. If almost never, the treatment is doing something. Every p-value later in the course answers exactly this question, with a formula instead of a shuffle.

Example
Two wards trial a hand-hygiene poster and the treated ward records 9 fewer infections. Shuffle the ward labels across the same records 10,000 times and count how often chance alone produces a gap of 9 or more. If that happens in 260 of the shuffles, the simulated p-value is 260/10,000 = 0.026 — rare enough to take seriously.

Week 2Sampling, random variables & population distributions

Population vs sample, parameter vs statistic

The population is everyone you want to conclude about; the sample is who you measured. A parameter (μ, p, σ) is the unknown truth about the population; a statistic (x̄, p̂, s) is what you computed from the sample. Greek letters are unknown; hats and bars are known. Hypotheses are always about parameters.

Example
A district wants the share of its schools whose drinking water exceeds a lead threshold. There is some true share p across all 340 schools — unknown, fixed. Test 60 schools at random and find 9 over the limit: p̂ = 0.15, known exactly, and a different number if you had drawn 60 other schools.

Four sampling methods

Simple random: every case equally likely. Stratified: split into homogeneous strata, then sample within each. Cluster: split into clusters, randomly pick whole clusters, measure everyone in them. Multistage: pick clusters, then sample within them. The distinction to memorise: within a stratum cases are similar and strata differ; within a cluster cases are varied and clusters resemble each other.

Example
Surveying a country's nurses. Simple random: draw 800 at random from the national register. Stratified: split by specialty — each internally similar — and draw 100 from each, guaranteeing every specialty appears. Cluster: pick 12 hospitals at random and survey every nurse in them, far cheaper because you visit 12 sites instead of 800. Multistage: pick the 12 hospitals, then sample 40 nurses within each.

Bias, and why a bigger sample cannot fix it

Bias is systematic error — the method pushes estimates away from the truth in a consistent direction. More data reduces variability, not bias, so a bigger biased sample just gives a precise wrong answer. Only a better sampling method fixes it. Common sources: convenience samples, non-response bias, and anecdotal evidence.

Example
A hospital surveys satisfaction by handing forms to patients as they walk out. That systematically excludes anyone still admitted, transferred, or deceased — exactly the patients whose care went worst. Collect 400 forms or 40,000: the estimate stays too high, and the larger sample only makes the margin of error look reassuringly small.
Longer explanations

Continuous distributions and density

For a continuous variable, probability is the area under the density curve, and the total area is 1. The probability of any single exact value is zero — which is why P(X < 5) and P(X ≤ 5) are identical for continuous variables, though not for discrete ones.

Example
Gestational age at birth is continuous. Asking “what is the probability a baby is born at exactly 39.000… weeks?” gives 0 — a single point has no width, so no area. The answerable version has width: P(38 < age < 40) is a real region under the curve and a real probability.

The normal distribution and Z-scores

The normal distribution is symmetric and bell-shaped, described entirely by μ and σ. The Z-score, Z = (x − μ)/σ, says how many standard deviations x lies above (positive) or below (negative) the mean. Standardizing is what lets one table serve every normal distribution. The 68–95–99.7 rule is the quick sanity check.

Example
Birth weight is roughly normal with μ = 3,400 g and σ = 500 g. A baby at 4,000 g has Z = (4000 − 3400)/500 = 1.20, so 1.2 SDs above average. A 2,500 g baby has Z = −1.80. By the 68–95–99.7 rule, about 95% of babies fall between 2,400 g and 4,400 g.

Reading normal tables in both directions

Tables give the area to the LEFT of a Z-score. Right tail = 1 − table value. Area between two values = (left area of the bigger) − (left area of the smaller). To go backwards from a percentile, find the probability inside the table, read off Z, then x = μ + Zσ. Always sketch the curve and shade first — it tells you whether the answer should be above or below 0.5.

Example
Birth weight, μ = 3,400, σ = 500. Below 2,500 g? Z = −1.80, and the table gives 0.0359 directly. Above 4,000 g? Z = 1.20 gives 0.8849 to the left, so the answer is 1 − 0.8849 = 0.1151. The heaviest 5% start where? The Z with 0.95 below it is 1.645, so x = 3400 + 1.645×500 = 4,222 g.

The binomial distribution

Counts successes in a fixed number of independent trials. P(k) = C(n,k) pk(1−p)n−k, with μ = np and σ = √(np(1−p)). Four conditions: trials independent, n fixed, each trial a success or failure, and p constant. For “at least one”, use the complement rather than summing.

Example
Eight patients are invited to a screening and each independently attends with probability 0.75, so p(miss) = 0.25. P(exactly 2 miss) = C(8,2)×0.25²×0.75⁶ = 28×0.0625×0.178 = 0.312. P(at least one misses) = 1 − 0.75⁸ = 0.900. μ = 8×0.25 = 2 and σ = √1.5 = 1.22.

Normal approximation to the binomial

When np ≥ 10 and n(1−p) ≥ 10, the binomial is close to a normal with the same μ = np and σ = √(np(1−p)). For an interval, apply the continuity correction: you are approximating unit-wide integer bars with a smooth curve, so extend the lower cutoff down by 0.5 and the upper cutoff up by 0.5. You always widen the region.

Example
n = 150 invitations with p = 0.40 attending. np = 60 and n(1−p) = 90, both ≥ 10, so the approximation holds with μ = 60 and σ = √36 = 6. For P(at least 70 attend), the bar for 70 begins at 69.5, giving Z = (69.5 − 60)/6 = 1.583 and P = 0.0567. Skip the correction and you get 0.0478 — a 16% relative error on a tail probability.

Week 3Confidence intervals for a proportion

Sampling distribution

The distribution of a statistic across all possible samples of a given size from the same population. You never observe one — you only ever have your single sample — but the whole of inference is reasoning about its shape, centre and spread. It is the bridge from “my one sample” to “what the population is like”.

Example
Imagine screening 250 children for untreated dental caries, recording p̂, then repeating with a fresh 250 — thousands of times. Those p̂ values pile into a bell centred on the true p with spread about 0.031. You only ever get one draw from that pile; the whole of inference is reasoning about the pile you cannot see.

Standard error vs standard deviation

s describes the spread of the data — how far individual observations sit from their mean. SE describes the spread of the estimate across hypothetical repeated samples, and shrinks like 1/√n. Confidence intervals and test statistics always use SE, never s. Conflating them is the most common conceptual error in the whole course.

Example
Screening 250 children finds p̂ = 0.38 with untreated caries. SE = √(0.38×0.62/250) = 0.031 — how much p̂ would bounce between repeat studies. Screen 1,000 children instead and SE halves to 0.015, while the children themselves are exactly as varied as before. The data did not change; the estimate got steadier.

Central Limit Theorem for a proportion

With independent observations and a large enough sample, the sampling distribution of p̂ is nearly normal, centred at the true p, with SE = √(p(1−p)/n). This is what makes z* × SE intervals legitimate. It needs both conditions — independence and success–failure — and when they fail, none of the formulas apply.

Example
Planning a colonoscopy-uptake study where p is believed near 0.45 with n = 300: np = 135 and n(1−p) = 165, both far above 10, so p̂ is nearly normal around 0.45 with SE = √(0.45×0.55/300) = 0.0287. That single fact is what lets you attach a probability to whatever p̂ the study returns.

The two conditions

Independence: a simple random sample, or random assignment in an experiment; and if sampling without replacement, n under 10% of the population. Success–failure: at least 10 successes and 10 failures. Which value you check with depends on what you are building — p̂ for a confidence interval, the null value p₀ for a test.

Example
250 children drawn at random from a district's registered pupils, 95 with untreated caries. Independence: a random sample, and 250 is well under 10% of the district. Success–failure: 95 successes and 155 failures, both comfortably ≥ 10. Conditions met — write that sentence out; it earns marks on its own.

The interval, and the margin of error

Every confidence interval in the course is point estimate ± (critical value) × SE. The half-width, (critical value)×SE, is the margin of error. For proportions the critical value is z*: 1.645 at 90%, 1.96 at 95%, 2.576 at 99%. Higher confidence means a larger z* and a wider — less informative — interval.

Example
p̂ = 95/250 = 0.380 with SE = 0.0307. At 95%, the margin of error is 1.96×0.0307 = 0.060, so the interval is 0.380 ± 0.060 = (0.320, 0.440). At 90% the same data give ±0.051 — narrower, but you are claiming less confidence in it.

What '95% confident' actually means

It is a property of the procedure, not of your one interval: repeat the whole study many times and about 95% of the intervals built this way would contain the true parameter. It is not a 95% probability that this interval contains the parameter — the parameter is a fixed number, so this interval either contains it or it does not.

Example
Correct: “We are 95% confident that the true proportion of children in this district with untreated caries is between 32.0% and 44.0%.”
Wrong: “There is a 95% probability the proportion lies in this interval” — the proportion is fixed, not random.
Wrong: “95% of children fall in this range” — that describes individuals, and the interval is about a single population number.

Choosing a sample size

Set the margin of error to your target and solve: n ≥ p(1−p)(z*/ME)². With no prior estimate use p = 0.5, which maximises p(1−p) at 0.25 and so gives the safest (largest) n. Always round up. Because ME depends on 1/√n, halving the margin of error quadruples the sample.

Example
Target ±4 percentage points at 95% for the caries survey. With no prior information use p = 0.5: n ≥ 0.25×(1.96/0.04)² = 600.2 → 601 children. Using last year's estimate of 0.38 instead: n ≥ 0.38×0.62×(49)² = 565.7 → 566. Knowing roughly where p sits saved 35 screenings.

Week 4Confidence intervals for a mean

CLT for the sample mean

With enough independent observations from a population with mean μ and SD σ, the sampling distribution of x̄ is nearly normal, centred at μ, with SE = σ/√n. In practice σ is unknown, so you use s/√n — and that substitution is exactly why the t-distribution exists.

Example
Twenty surgical wounds are followed to healing; the sample gives s = 3.4 days. Then SE = 3.4/√20 = 0.76 days. Note what that is not: the spread of individual healing times is 3.4 days. The 0.76 is how much the average of twenty wounds would move between repeat studies.

Why t instead of z

Replacing the unknown σ with the sample's s adds uncertainty the normal model does not account for. The t-distribution has the same bell shape with thicker tails, so critical values are larger and intervals wider — the honest price of not knowing σ. The rule is about knowledge, not size: σ unknown → use t, however large n is.

Example
With n = 20, df = 19 and t* = 2.093 against z* = 1.960. On SE = 0.76 that is a margin of error of 1.59 days rather than 1.49 — about 7% wider. Using z would quietly overstate how precisely you know the mean.

Degrees of freedom

The parameter that sets the shape of the t, chi-square and F distributions. For a one-sample t, df = n − 1. Larger df means thinner tails and closer to normal. Getting df wrong is a silent error — the resulting p-value still looks entirely plausible, so nothing warns you.

Example
t* for a 95% interval, by df: df = 9 → 2.262; df = 19 → 2.093; df = 49 → 2.010; df = 99 → 1.984, closing on z* = 1.960. Across the course: n−1 for one sample or paired, n−2 for a regression slope, k−1 and n−k for ANOVA.

The normality condition

Two rules of thumb. With n < 30, require no clear outliers and assume the population is nearly normal. With n ≥ 30, require no particularly extreme outliers — the CLT absorbs moderate skew. Strongly skewed data need a larger n still. Judge this from a histogram or box plot, never from n alone.

Example
n = 20 wounds with a box plot showing no outliers → fine; state the assumption explicitly. n = 60 with mild right skew → fine, the CLT covers it. n = 13 travel-claim amounts with two values ten times the rest → not fine — small sample, extreme outliers, so the t-procedure does not apply.

The t-interval

x̄ ± t*df × s/√n, with df = n − 1. Built in the same four steps as every other procedure: prepare (identify x̄, s, n and the confidence level), check the conditions, calculate, conclude in context naming the population and the units.

Example
Twenty wounds heal in a mean of 12.6 days with s = 3.4. SE = 0.760, df = 19, t* = 2.093. Interval: 12.6 ± 2.093×0.760 = 12.6 ± 1.59 = (11.01, 14.19) days. Conclusion: “We are 95% confident the true mean healing time is between 11.0 and 14.2 days.”

Week 5Introduction to hypothesis testing

H0 and HA

H₀ is the skeptical position — no effect, no difference, status quo — and is always an equality at the null value. Hₐ is the claim requiring evidence. Both are about parameters, never statistics. The court analogy: H₀ is the presumption of innocence, rejected only on strong evidence.

Example
“Has hand-hygiene compliance moved from the audited baseline of 62%?” → H₀: p = 0.62, Hₐ: p ≠ 0.62.
“Did grip strength change after the training?” → H₀: μd = 0, Hₐ: μd ≠ 0.
Never “H₀: p̂ = 0.62” — you measured p̂; there is nothing left to hypothesise about it.

The p-value

The probability of observing data at least as extreme as what you got, computed assuming H₀ is true. Small means the data would be surprising under H₀, which is evidence against it. It is not the probability that H₀ is true, and not the probability you made a mistake.

Example
An audit of 180 hand-hygiene opportunities gives p = 0.027. Read it as: if compliance really were still 62%, there would be about a 2.7% chance of an audit landing this far from 62% or further. It is not a 2.7% chance that compliance is still 62%.

A test uses p0, a CI uses p̂

A test supposes H₀ is true, so it builds the standard error from the null value: SE = √(p₀(1−p₀)/n). A confidence interval supposes nothing, so it uses . Same rule extends to two proportions, where a test of p₁ = p₂ uses the pooled proportion. Using the wrong one is a real error, not rounding.

Example
180 observations, 126 compliant, tested against a baseline of p₀ = 0.62. p̂ = 0.700.
Correct (test): SE = √(0.62×0.38/180) = 0.0362, Z = 2.211, p = 0.027.
Wrong: SE = √(0.70×0.30/180) = 0.0342, Z = 2.342, p = 0.019 — a different, more confident-looking number answering a question nobody asked.

Type 1 and Type 2 errors

Type 1: rejecting a true H₀ — a false alarm, at rate α. Type 2: failing to reject a false H₀ — a miss, at rate β. Lowering α always raises the Type 2 rate; only a bigger sample improves both. Choose α by which mistake costs more in context — 0.05 is convention, not law.

Example
Newborn hearing screening. Type 1 = refer a hearing baby for further testing (parental anxiety, a wasted clinic slot). Type 2 = miss a deaf newborn, delaying language development for months. Type 2 is far worse, so screen with a large α.
Ordering a CT scan. Type 1 = irradiate someone who did not need it. Type 2 = miss a bleed. Here the balance is genuinely close, which is why guidelines, not reflex, set the threshold.

One-sided vs two-sided

Decide from the research question before seeing the data. “Is there a difference / has it changed?” is two-sided. “Is it an improvement?” is one-sided, but only if that direction was specified in advance. Choosing one-sided after seeing which way the data went doubles your real Type 1 error rate. When unsure, use two-sided.

Example
The hand-hygiene audit gives a two-sided p of 0.027. Reporting only the upper tail would give 0.0135 — twice as impressive, and legitimate only if “compliance has risen” was the stated hypothesis before the audit. Deciding afterwards, because that is the way the data fell, is not.

Paired data

Two sets of observations are paired when each observation in one has exactly one natural partner in the other — the same subject before and after, twins, left and right eye, matched cases. The method is simply: compute the differences, then run a one-sample t on them. n is the number of pairs, and normality is checked on the differences.

Example
Eight nurses have grip strength measured before and after a six-week programme, giving eight differences with d̄ = 2.63 kg, sd = 0.52, and df = 7. Because each nurse is her own control, the between-person variation cancels — which is exactly why the paired design detects a 2.6 kg shift that two independent groups of eight would struggle to see.

Week 6Inferential methods for comparing means

The two-sample t procedure

The estimate is x̄₁ − x̄₂, the null value is 0, and SE = √(s₁²/n₁ + s₂²/n₂). Notice the variances add even though you subtract the means — comparing two noisy quantities is noisier than either alone.

Example
Lab turnaround times, in minutes. Site A: n = 35, x̄ = 42.1, s = 8.2. Site B: n = 31, x̄ = 37.4, s = 6.9.
SE = √(8.2²/35 + 6.9²/31) = √(1.921 + 1.536) = 1.859. The difference is 4.7 minutes, so t = 4.7/1.859 = 2.528 on df = 30, giving p = 0.017.
Longer explanations

Degrees of freedom, two ways

The exact two-sample df (Welch–Satterthwaite) is messy, so software computes it and reports a decimal. By hand, use the conservative min(n₁−1, n₂−1), which gives a slightly wider interval and errs safe. Both are acceptable — just say which you used.

Example
n₁ = 35 and n₂ = 31 give df = 30 by hand — min(34, 30). Software's Welch formula returns about 64 for the same data. The by-hand version yields the wider, more cautious interval; both reach the same conclusion. Say which you used.

Conditions, checked per group

Independence, extended: within each group and between the groups — satisfied by two independent random samples or by random assignment. Normality: checked separately in each group, using the same n < 30 / n ≥ 30 rules of thumb. One well-behaved group does not excuse the other.

Example
“The two sites operate independently and no sample was drawn from the other, so observations are independent within and between groups. With n = 35 and n = 31 both above 30, and box plots showing no extreme outliers in either site, the sampling distribution of the difference in means is nearly normal.”
Longer explanations

Paired or independent?

Ask: could you shuffle one column without breaking anything? If shuffling destroys a real correspondence, the data are paired and you work with differences. If it destroys nothing, the groups are independent. Matched pairs count as paired by design, even though two different people are involved — that is the case that catches people.

Example
Paired: blood pressure in a patient's left and right arm; a lab sample split and sent to two analysers; twins assigned to different programmes.
Independent: turnaround times at two different labs; patients at clinic A versus clinic B; this year's intake versus last year's. Test it by asking whether shuffling one column destroys a real correspondence.

What a non-significant result does not mean

“Fail to reject” is not evidence of no effect. It means the study could not distinguish the observed difference from zero — often because it was too small. The confidence interval shows what is still plausible, which is why it belongs next to every p-value. Absence of evidence is not evidence of absence.

Example
A 22-patient pilot finds a 1.8-point difference in a fatigue score with SE = 1.4, so t = 1.29 on df = 21 and p = 0.21. But the 95% interval runs (−1.11, 4.71) — it contains 0, and also contains a 4.7-point benefit that would matter enormously. The study did not find nothing; it could not tell those two apart.

Pooled standard deviation

If the two populations genuinely have equal SDs, they can be combined: s²pool = ((n₁−1)s₁² + (n₂−1)s₂²)/(n₁+n₂−2), with df = n₁+n₂−2. This is not the default — only pool when background knowledge supports equal population SDs. The benefit shrinks as samples grow; the cost of being wrong does not.

Example
For the two labs, s²pool = (34×8.2² + 30×6.9²)/64 = 58.04, so spool = 7.62 with df = 64 instead of 30. That larger df is the attraction — but it is only earned if you genuinely believe the two labs have equal population SDs, and 8.2 versus 6.9 is not strong evidence of that.
Longer explanations

Week 7Study design & more sampling

Observational vs experimental

In an observational study the researcher records what is already true and can claim association only, because a confounder may drive both variables. In an experiment the researcher assigns treatments, and random assignment balances confounders across groups — which is what buys causation.

Example
Observational: compare hearing thresholds between factory floor staff and office staff at the same firm. Floor staff are older, more often male, and have longer service — none of which you can peel apart from the noise.
Experimental: issue two different ear defenders at random across the floor. Age and service are now balanced by the draw, so a hearing difference is attributable to the defenders.

The two 'randoms'

Two separate design choices with two separate consequences. Random sampling — how cases got into the study — buys generalizability to the population sampled. Random assignment — how cases got into groups — buys causality. A study can have either, both, or neither, and exams ask for both answers with different reasons.

Example
Take a literacy programme in schools.
Random sample, no assignment — survey randomly chosen schools and correlate library spending with reading scores: generalizes, association only.
One school, pupils randomly assigned — causal, but only for pupils like those.
Both — randomly chosen schools, pupils randomly assigned inside each: causal and generalizable.
Neither — compare pupils who already joined the book club with those who did not: association, for these pupils only.

Confounding variables

A variable related to both the explanatory and the response variable, offering a rival explanation for the association you observed. Naming one that touches only the response earns nothing — you have to state both links. Random assignment is the only thing that neutralises confounders you have not thought of.

Example
People who take vitamin D supplements have fewer fractures. Outdoor activity is a confounder because it is linked to both: active people are more likely to take supplements and have stronger bones and better balance. By contrast, “older people fracture more” is not yet a confounder — you would have to show age is also linked to supplement use.
Longer explanations

Four principles of experimental design

Control possible confounders by holding conditions constant. Randomize subjects into groups, which balances the confounders you did not think of. Replicate with enough subjects for the result to be reliable. Block on variables expected to influence the response — group similar subjects and randomize within each block.

Example
A wound-dressing trial. Control: identical dressing-change schedules and follow-up in both arms. Randomize: assign by sealed envelope rather than by which nurse is on shift. Replicate: run the power calculation and enrol what it says, not the 30 patients who happen to be available. Block: wound size drives healing, so split into small and large and randomize within each.

Blinding and placebo

Blind means the subject does not know which group they are in — a placebo is what makes that possible. Double-blind means neither the subject nor the person assessing them knows. Blinding controls the placebo effect and assessor bias, both of which are real and measurable.

Example
An acupuncture trial uses sham needles that retract instead of penetrating, so patients cannot tell which arm they are in. If the clinician scoring pain is also kept unaware, the trial is double-blind. Without the sham, any benefit could be the placebo effect plus the attention of a practitioner — neither of which is the needle.

Power

Power = 1 − β: the probability of rejecting H₀ when Hₐ is actually true — the chance of detecting a real effect of a stated size. It rises with a larger sample, a larger true effect, a larger α, and a smaller σ. Only n is under your control after the fact.

Example
A trial with 80% power and a true effect present will still fail to reject one time in five. Run the same trial with 25 patients per group where 120 were needed and power might be 30% — so a null result tells you almost nothing about the treatment, only that the study was too small to see it. This is why power is computed before enrolment.
Longer explanations

Planning a sample size

Fix the effect worth detecting (d), the population SD (σ), α, and the power you want, then solve for n. For comparing two means with equal groups: n per group = 2σ²(zα/2 + zβ)²/d². Because n scales with 1/d², small effects are dramatically more expensive to detect. Do this before collecting data.

Example
Detecting a 0.4 mmol/L difference in cholesterol with σ = 1.1, α = 0.05 and 80% power: n = 2×1.1²×(1.960+0.842)²/0.4² = 118.7 → 119 per group. Raise power to 90% and it becomes 159. Care only about a 0.8 difference and it drops to 30 — doubling the target effect quartered the trial.

Week 9ANOVA

Why not many t-tests

With k groups there are k(k−1)/2 pairs, and each test carries its own α chance of a false positive. Run enough of them and a spurious “significant” result becomes likely. ANOVA asks the whole question once, at one α.

Example
Comparing 6 hospitals means K = 6×5/2 = 15 pairwise tests. If every null is true and each test runs at α = 0.05, the chance of at least one false positive is roughly 1 − 0.9515 = 54%. You would find a “difference” more often than not, purely by testing a lot.

The F statistic

F = MSG/MSE. MSG (mean square between groups) measures how far apart the group means are; MSE (mean square error) measures the noise inside the groups. If H₀ is true both estimate the same variance and F lands near 1. A large F means the means are spread out relative to the noise — evidence against H₀. Upper tail only.

Example
Monthly falls across three wards give SSG = 48.53 on df 2, so MSG = 24.27; and SSE = 25.20 on df 12, so MSE = 2.10. F = 24.27/2.10 = 11.56, and P(F > 11.56) on (2, 12) df = 0.0016. The ward means are spread far wider than within-ward noise would explain.

Reading an ANOVA table

The degrees of freedom tell you the design, and reading them backwards is a standard exam move. Group row: df = k − 1, so k is that plus one. Residual row: df = n − k, so n is that plus k. Mean Sq = Sum Sq / df on each row, and F is the ratio of the two Mean Sq values.

Example
Df Sum Sq Mean Sq F Pr(>F)
ward 2 48.53 24.27 11.556 0.0016
Residuals 12 25.20 2.10

df 2 on the ward row → k = 3 wards. df 12 on residuals → n = 12 + 3 = 15 ward-months in total.
Longer explanations

ANOVA conditions

Independence — always required, and the one most likely to be violated. Normality within each group — matters most when the groups are small. Constant variance across groups — matters most when the group sizes are unequal. Check with side-by-side box plots and residual plots.

Example
Five months of data from each of three wards: the groups are small, so normality matters — look hard for a single freak month. But the group sizes are equal, which makes ANOVA forgiving about unequal spread. Flip it to wards with 40, 12 and 9 months and unequal variance becomes the condition to worry about.
Longer explanations

Multiple comparisons and Bonferroni

A significant F licenses exactly one sentence: at least one mean differs. To find which, run pairwise tests at a stricter level: α* = α/K where K = k(k−1)/2. It is entirely possible to reject with ANOVA and then find no significant pair — that does not invalidate the ANOVA, it means the evidence was spread rather than concentrated.

Example
With k = 5 groups, K = 5×4/2 = 10 pairs and α* = 0.05/10 = 0.005. A pairwise comparison returning p = 0.03 would have passed as a standalone test and now clearly fails — which is exactly the inflation the correction exists to remove.

Week 102x2 tables: odds ratios and relative risks

The 2x2 table

Everything this week comes out of one table, so set it up the same way every time: exposure on the rows, outcome on the columns. Cells are labelled a, b, c, d reading across then down. Risk is computed across a row — which is why orientation has to be right before any arithmetic.

Example
Malaria No malaria Total
Bed net 35 285 320
No bed net 59 221 280

a = 35, b = 285, c = 59, d = 221. Risk in the exposed row is 35/320 = 0.109; in the unexposed row, 59/280 = 0.211. Here the “exposure” is protective, which is common and changes nothing about the arithmetic.

Risk vs odds

Risk is cases divided by everyone at risk — a probability, between 0 and 1. Odds is cases divided by non-cases — unbounded above. They convert: odds = p/(1−p) and p = odds/(1+odds). Keeping them apart is what stops you attaching the wrong verb to a ratio later.

Example
In the bed-net group the risk of malaria is 35/320 = 0.109, so the odds are 35/285 = 0.123 — close, because the outcome is uncommon. Without a net the risk is 0.211 and the odds are 59/221 = 0.267. As the outcome gets more common the two numbers separate fast: a risk of 0.9 is odds of 9.

Risk difference, relative risk, odds ratio

Three ways to compare two groups. RD = p₁ − p₀ is absolute, null value 0. RR = p₁/p₀ is relative, null value 1. OR = ad/bc (the cross-product) is the ratio of odds, null value 1. Comparing a ratio against 0 is a guaranteed wrong answer.

Example
From p₁ = 0.109 (net) and p₀ = 0.211 (no net):
RD = 0.109 − 0.211 = −0.101, i.e. 10.1 percentage points lower.
RR = 0.109/0.211 = 0.519 — net users were about half as likely to get malaria.
OR = (35×221)/(285×59) = 0.460. All three are below their null value, which is what a protective effect looks like.

Confidence intervals go through the log

RR and OR are bounded below by 0 and unbounded above, so their sampling distributions are right-skewed and a symmetric ± interval would be wrong — it can even dip below zero, which is impossible for a ratio. Three steps: take ln, build a symmetric interval there, then exponentiate both endpoints. SE(ln OR) is just the reciprocals of the four cells.

Example
OR = 0.460 with SE(ln OR) = √(1/35 + 1/285 + 1/59 + 1/221) = 0.231. ln(0.460) = −0.777, so −0.777 ± 1.96×0.231 = (−1.230, −0.323); exponentiating gives (0.292, 0.724). It sits 0.168 below the estimate and 0.264 above — asymmetric, which is the signature of a correct log interval. It excludes 1, so the protection is significant.

Study design decides which measure you can use

In a cohort study or trial, subjects are grouped by exposure and followed, so risk is observable and RD, RR and OR are all available. In a case–control study, subjects are recruited by outcome — the researcher chooses how many cases and controls — so the column totals are an artifact of recruitment, risk is not estimable, and only the OR survives. That is the entire reason the odds ratio exists.

Example
A study recruits 180 patients admitted with a hip fracture and 180 matched non-fractured patients, then checks whether each had been prescribed a sedative: 100 of the fracture group and 61 of the others had. You cannot compute risk — the 1:1 recruitment ratio was the researcher's choice, not a fact about the population. The odds ratio is still valid: (100×119)/(61×80) = 2.44.

When OR approximates RR

Only when the outcome is rare — a common rule of thumb is under about 10% in both groups. Then b ≈ a+b and d ≈ c+d, so ad/bc ≈ the risk ratio. When the outcome is common, the OR is always further from 1 than the RR, so reporting it as a risk ratio overstates the effect.

Example
Fix the true relative risk at 3.0 and vary how common the outcome is:
3% vs 1% (rare): OR = 3.06 — interchangeable.
30% vs 10%: OR = 3.86.
60% vs 20%: OR = 6.00, double the true risk ratio. Calling that last one “six times as likely” misstates the effect by a factor of two.

Relative vs absolute, and NNT

A relative measure can look dramatic while the absolute change is trivial, which is how press releases overstate findings. NNT = 1/|RD|, rounded up, converts the absolute difference into “how many people must be treated to prevent one event”. Report both a relative and an absolute measure.

Example
The bed nets give RD = −0.101, so NNT = 1/0.101 = 9.9 → 10: distribute ten nets to prevent one case of malaria. Compare a drug that cuts a risk from 4 in 10,000 to 2 in 10,000 — the same headline “halves your risk”, but NNT = 5,000. The relative measure is identical; the absolute one is not remotely.

Week 11Hypothesis testing for two or more categories

Two proportions

A confidence interval estimates each group separately: SE = √(p̂₁(1−p̂₁)/n₁ + p̂₂(1−p̂₂)/n₂). A test of H₀: p₁ = p₂ supposes they are the same, so it pools all the data to estimate that shared value. Same logic as p₀ vs p̂ in week 5.

Example
HPV vaccine uptake: 132 of 220 at clinic A, 91 of 190 at clinic B.
Test:pool = 223/410 = 0.544, SE = √(0.544×0.456×(1/220 + 1/190)) = 0.0493, Z = 2.454, p = 0.014.
Interval: SE = √(0.600×0.400/220 + 0.479×0.521/190) = 0.0490, giving (0.025, 0.217). Different SEs, because a test assumes the proportions are equal and an interval does not.

Chi-square goodness of fit

One categorical variable with k categories, testing whether the observed counts match a claimed distribution. X² = Σ(O − E)²/E over all cells, with df = k − 1. If H₀ says all categories are equally likely, E = n/k; if it specifies proportions, E = n×(claimed proportion). Always counts, never proportions.

Example
A blood bank records 250 donors by type: O 92, A 74, B 38, AB 46. Testing “all four types equally likely” gives E = 250/4 = 62.5 for each. X² = (29.5² + 11.5² + 24.5² + 16.5²)/62.5 = 30.0 on df = 3, p < 0.0001. Reject — and the cell-by-cell gaps show type O is the driver.

Chi-square test of independence

Two categorical variables in a two-way table, testing whether they are associated. Expected counts come from E = (row total × column total)/table total — which is just P(A and B) = P(A)P(B) rewritten in counts. df = (R−1)(C−1). A significant result says an association exists, not which cells or which direction.

Example
Surgical site infection across three wards of 80 operations each. Expected count for ward 1 / infected = (80×48)/240 = 16.0. Summing (O−E)²/E over all six cells gives X² = 10.47 on df = (3−1)(2−1) = 2, p = 0.0053. Ward and infection are associated — but the test alone will not tell you which ward is the problem.

Conditions

Two, for any chi-square test. Independence: each case contributes a count to exactly one cell. Sample size: every expected count is at least 5 — the expected count, not the observed one. If a cell falls short, the usual remedy is to combine categories.

Example
A five-category survey has expected counts of 40, 35, 28, 4 and 3. The last two break the “at least 5 expected” rule, so merge them into a single “other” category with expected 7 — which also drops df from 4 to 3. Note the rule is about expected counts: a cell with 2 observed but 11 expected is perfectly fine.

Upper tail only

X² measures total squared deviation from expectation, so it can only be large when the fit is poor — there is no “too good” direction to test. The p-value is always the area to the right. Do not double it to make it two-sided; it is already the whole test. The same is true of the F-test in ANOVA.

Example
X² = 30.0 on df = 3 gives p = P(X² > 30.0), the area to the right. Doubling it for “two-sidedness” is wrong — a small X² just means the observed counts sat close to what H₀ predicted, which is not evidence of anything. The distribution only exists for values ≥ 0.
Longer explanations

2x2: z-test and chi-square agree

On a 2×2 table the two-proportion z-test and the chi-square test of independence are the same test: z² = X² and the p-values match exactly. Use whichever the question asks for — the z-test additionally gives you a confidence interval for the difference, which chi-square cannot.

Example
For the HPV uptake comparison the two-proportion z-test gives Z = 2.454, so Z² = 6.02. Running a chi-square test of independence on the same 2×2 table returns X² = 6.02 and an identical p-value of 0.014. They are the same test written two ways.

Week 12Correlation & simple linear regression

The model and residuals

The fitted model is ŷ = b₀ + b₁x, and the residual of a point is e = y − ŷ — observed minus predicted. A positive residual means the point sits above the line and the model under-predicted; negative means it over-predicted.

Example
Nightly sleep (hours) against next-day reaction time (ms) fits ŷ = 381.2 − 14.14x. Someone sleeping 5.0 hours is predicted at 381.2 − 70.7 = 310.5 ms. If they actually recorded 330 ms, the residual is 330 − 310.5 = +19.5 — slower than the model expected, so the point sits above the line.

Reading a residual plot

Plot residuals against x or against fitted values. It magnifies what a scatterplot hides. A good fit shows a structureless horizontal band. Curvature → the relationship is not linear. Fanning → non-constant variance. A trend in collection order → the residuals are not independent — the one problem a plot of y against x will never reveal.

Example
A clean band around zero with no shape → nothing to fix.
A downward-then-upward curve → linearity fails; try a transformation or a quadratic term.
A widening wedge → constant variance fails; the model is far more precise at one end than the other.
A slow drift across the collection sequence → independence fails, and no plot against x would have shown it.

Correlation R

R measures the strength and direction of a linear relationship, always between −1 and 1. Describe it with three words: strength (weak / moderate / strong), direction (positive / negative), and linear. R near 0 means no linear relationship — not no relationship at all.

Example
R = −0.55 between sleep hours and reaction time is a moderate, negative, linear association: more sleep, faster reactions. But consider caffeine and performance — better up to a point, worse beyond it. That inverted-U can give R near 0 while being strongly, predictably related, which is why the scatterplot comes first.

Least squares

The least squares line minimises the sum of squared residuals — which is why one extreme point can dominate the fit. From summary statistics, b₁ = (sy/sx)R, and because the line always passes through (x̄, ȳ), b₀ = ȳ − b₁x̄. Remember that fact and you never need the intercept formula.

Example
sx = 1.4 hours, sy = 36 ms, R = −0.55, x̄ = 6.8, ȳ = 285.
b₁ = (36/1.4)×(−0.55) = −14.14.
b₀ = 285 − (−14.14)×6.8 = 381.17.
So ŷ = 381.17 − 14.14x, and you can check it passes through (6.8, 285).

Interpreting slope and intercept

The slope is the estimated difference in y between cases whose x differs by one unit — a difference between cases, “on average”, and causal only if the data came from a randomized experiment. The intercept is the mean y at x = 0, which is meaningless whenever x = 0 sits outside the data. Say so when it does.

Example
“For each additional hour of sleep, the model predicts a reaction time 14.1 ms faster, on average.” That compares people who differ by an hour; it does not promise that one person sleeping an extra hour gains 14.9 ms, and it is not causal because nobody assigned sleep. The intercept 381.2 is the prediction at zero hours of sleep — outside any sane range.

R-squared

is the square of the correlation, and is the proportion of the variability in y that the model explains. It runs from 0 to 1. R keeps the direction; R² keeps only the strength — R = −0.5 and R = +0.5 both give R² = 0.25. To recover R from R², take the square root and get the sign from the slope.

Example
R = −0.55 → R² = 0.303: about 30% of the variability in reaction time is explained by the model using sleep hours. The other 70% is everything else — age, caffeine, time of day, measurement noise. It does not mean 30% of the points lie on the line.

Extrapolation

Predicting outside the observed range of x. The data give no evidence the linear pattern continues out there, so the model does not support it — however confident the arithmetic looks. This is also why an intercept is usually uninterpretable: x = 0 is an extrapolation in most real data sets.

Example
The sleep data run from about 4.5 to 9 hours. Feeding 2 hours into ŷ = 381.17 − 14.14x returns 352.9 ms, and the arithmetic looks perfectly confident — but no one in the study slept 2 hours, so the line has no evidence out there. Push far enough and the model predicts a negative reaction time, which is the giveaway.
Longer explanations

Week 13Inference for simple linear regression

The LINE conditions

Linearity — the relationship really is a straight line. Independent residuals. Nearly normal residuals. Equal variance of residuals. All four are judged on the residuals, not on the original scatterplot, and software will happily fit a line to a curve without warning you.

Example
Check L and E together on residuals-versus-fitted: you want an even, shapeless band. Check N on a normal probability plot of the residuals — points drifting off the line at the ends mean heavy tails. Check I by plotting residuals against the order the data were recorded, which is the only place non-independence ever shows up.

Outlier, leverage, influence

Three different things. An outlier is far from the cloud of points. High leverage means far from the centre horizontally — extreme in x, and judgeable before the line is fitted. An influential point is a high-leverage point that visibly moves the line when removed. Leverage is the opportunity; influence is the effect.

Example
Data span x = 2 to 12.
A point at x = 7 sitting far below the line → outlier, low leverage; it shifts the line slightly but hardly tilts it.
A point at x = 40 lying near the extended line → high leverage, not influential: it has the power and does not use it.
A point at x = 40 far off the line, whose removal changes the slope from 2.3 to 0.9 → high leverage and influential. Report the fit both ways.

Testing the slope

H₀: β₁ = 0 means no linear relationship. The statistic is t = b₁/SEb₁ with df = n − 2 — two parameters were estimated, so you lose two. Using n − 1 gives a plausible-looking p-value that is quietly wrong. Testing the slope against 0 is the same test as asking whether the correlation is 0.

Example
A model of crop yield on rainfall gives b₁ = 2.31 with SE = 0.62 from n = 28 fields. df = 28 − 2 = 26, t = 2.31/0.62 = 3.726, and the two-sided p is 0.00095. Reject H₀: there is strong evidence of a positive linear relationship.

Reading regression output

The Estimate column gives b₀ and b₁. The t value is simply Estimate ÷ Std. Error. Pr(>|t|) is the two-sided p-value for that coefficient against 0. The residual degrees of freedom line tells you n — add 2 for simple regression. Multiple R-squared is R²; its square root is |R|, with the sign from the slope.

Example
Estimate Std. Error t Pr(>|t|)
(Intercept) 14.802 3.114 4.75 0.00006
rainfall 2.310 0.620 3.73 0.00095

Residual standard error: 6.41 on 26 degrees of freedom
Multiple R-squared: 0.348

26 df → n = 28. R = +√0.348 = 0.590, positive because the slope is.

Confidence interval for a coefficient

b₁ ± t*df × SEb₁, with df = n − 2. It will exclude 0 exactly when the two-sided test rejects at the matching level — the same agreement between intervals and tests as everywhere else in the course.

Example
b₁ = 2.31, SE = 0.62, df = 26 so t* = 2.056. Interval: 2.31 ± 2.056×0.62 = (1.04, 3.58). It excludes 0, matching p = 0.00095 — so each extra centimetre of rainfall is associated with somewhere between 1.0 and 3.6 more units of yield.

Week 14Multiple linear regression

The multiple regression model

A linear model with several predictors: ŷ = b₀ + b₁x₁ + … + bkxk, with df = n − k − 1. Each coefficient is estimated by software. The point of adding predictors is to adjust each coefficient for the others.

Example
Days of school absence modelled on distance from school (km), household size, and school type (state / academy / independent): ŷ = 3.1 + 0.42×distance + 0.65×household − 1.20×academy − 2.05×independent. School type contributes 2 to k, so k = 4, and with n = 90 the residual df is 90 − 4 − 1 = 85.
Longer explanations

'Holding all else constant'

Each coefficient is the estimated difference in y per one-unit larger xi with the other predictors fixed. That clause is not decoration — drop it and you are describing a different (simple-regression) quantity. Every interpretation you write in this chapter must contain it.

Example
“Among pupils at the same school type and from households of the same size, each additional kilometre of distance is associated with 0.42 more days of absence, on average.” Delete the bolded clause and the sentence claims something the model never estimated.
Longer explanations

Why a coefficient can flip sign

A simple-regression coefficient silently absorbs the effect of everything correlated with it that was left out. The multiple regression coefficient has been adjusted for those variables, so it can shrink, grow, or reverse. This is expected behaviour and is usually the point of fitting the bigger model.

Example
Distance alone predicts 0.71 extra absence days per kilometre. Add household size and it falls to 0.42. Larger households live further out and miss more school for other reasons, so the simple model was crediting distance with part of the household effect. Adjusting for it leaves distance's own contribution.

Categorical predictors and the reference level

A categorical predictor with p levels gets p − 1 coefficients. The level with no coefficient is the reference level, and every other coefficient is measured against it — never in absolute terms. It also contributes p − 1 to k, which changes both df and adjusted R².

Example
School type has three levels but only academy and independent get coefficients — so state is the reference. A coefficient of −2.05 on independent means “independent-school pupils miss 2.05 fewer days than state pupils at the same distance and household size”. It is a comparison, never an absolute.

Adjusted R-squared

Plain R² never decreases when you add a predictor, even a worthless one, so it cannot compare models of different sizes — chasing it always selects the biggest model. Adjusted R² penalises the number of predictors and can go down. The model where it peaks is the one to report.

Example
n = 90, adding predictors one at a time. R² climbs every step: 0.181 → 0.472 → 0.516 → 0.518. Adjusted R² goes 0.1717 → 0.4599 → 0.4991 → 0.4953 — it falls at the fourth step, so that predictor earned less than it cost. Report the three-predictor model.

Diagnostic plots

The LINE conditions, read off four plots. Residuals vs fitted values → linearity and equal variance. Normal probability plot of residuals → normality. Residuals vs each predictor → curvature the overall plot missed. Residuals in collection order → independence.

Example
In R, plot(fit) gives the standard four. A funnel in residuals-versus-fitted → transform the response. A curve → the linear form is wrong. Points bending off the ends of the normal probability plot → heavy tails, which matters most when n is small. And always add one the default set omits: residuals against the order the data were collected.

Collinearity

Two predictors carrying nearly the same information are collinear. Their individual coefficients become unstable and their standard errors inflate, so neither looks significant even though together they clearly matter. It is a common reason a p-value-based selection drops something it should keep.

Example
Put both household size and number of children in the household into the absence model and neither will look significant, because they carry almost the same information and the fit cannot apportion credit. The tell-tale sign: a strong overall F-test alongside a table of individually non-significant coefficients.
Longer explanations

Reference

Which test do I use?

Three questions settle it. What kind of response variable? How many groups? Paired or independent?

Response Groups Structure Procedure df Week
Categorical1 proportion1-proportion z3, 5
Categorical2 proportionsindependent2-proportion z11
Categorical2 proportions2×2 tablerelative risk / odds ratioCI vs 110
Categorical1 variable, k categorieschi-square goodness of fitk − 111
Categorical2 variablestwo-way tablechi-square test of independence(R−1)(C−1)11
Numerical1 mean1-sample tn − 14, 5
Numerical2 meanspairedpaired t on the differencesnpairs − 15
Numerical2 meansindependent2-sample tmin(n1−1, n2−1)6
Numerical3+ meansindependentANOVA (F-test)k−1 and n−k9
Numerical2 numerical variableslinear regressionn − 212, 13
Numericalseveral predictorsmultiple regressionn − k − 114

Reference

The mistakes that cost marks

These come up again and again, and every one of them is cheap to avoid once you know to look.

  1. Paired read as independent

    “30 patients before and after” gives 30 differences with df = 29, not two samples of 30 with df = 58. The most-missed distinction in the course.

  2. The wrong standard error

    A confidence interval uses p̂. A hypothesis test uses the null value p0, because the test supposes H0 is true. For two proportions the test uses the pooled proportion.

  3. Comparing a ratio against 0

    Relative risks and odds ratios are compared against 1. A CI of 0.85 to 1.40 contains 1, so there is no significant association.

  4. “Accepting” the null

    Failing to reject is not evidence of no effect. Say “the data do not provide sufficient evidence that…”

  5. Confidence stated as probability

    “There is a 95% probability the parameter is in this interval” is wrong. The parameter is fixed; the 95% describes the procedure.

  6. ANOVA over-read

    A significant F licenses only “at least one mean differs” — never “the means are all different”.

  7. Risk from a case–control study

    Subjects were selected on the outcome, so the row totals are an artifact of recruitment. Only the odds ratio is available.

  8. Causation from observation

    Random sampling buys generalizability; random assignment buys causality. Different mechanisms, and exams ask for both.

Reference

How to word it

Most of the writing marks in an intro course come from a handful of sentences. These are the shapes they take.

A confidence interval

We are 95% confident that the true mean commute time for all employees at this company is between 21.4 and 26.8 minutes.

Name the confidence level, the population (not the sample), and the units.

A p-value

If the medication truly had no effect, there would be a 3.2% chance of seeing a difference at least as large as the one we observed.

P(data this extreme or more | H0 true). Not the probability that H0 is true.

Rejecting H0

p = 0.008 < α = 0.05, so we reject H0. The data provide strong evidence that mean recovery time is shorter on the new drug.

Always restate HA in context.

Failing to reject H0

p = 0.21 > α = 0.05, so we fail to reject H0. The data do not provide sufficient evidence that the recovery times differ.

Never “accept”, never “proved”.

A regression slope

For each additional $1,000 of family income, the model predicts gift aid to be $0.43 lower, on average.

Say “on average”, and frame it as a difference between cases.

A relative risk

Smokers were 2.4 times as likely to develop the disease as non-smokers (RR = 2.4, 95% CI 1.6 to 3.6).

“Times as likely” for RR.

An odds ratio

The odds of the disease were 2.4 times higher among smokers than non-smokers (OR = 2.4, 95% CI 1.5 to 3.8).

“Times the odds” for OR — never swap the two verbs.

Reference

Formulas

Every procedure in the course is the same two shapes with a different standard error.

The skeleton

Confidence interval
point estimate ± (critical value) × SE
Test statistic
(point estimate − null value) / SE
Margin of error
ME = (critical value) × SE
Common z*
1.645 (90%) · 1.960 (95%) · 2.576 (99%)

Proportions

SE for a CI
√( p̂(1−p̂) / n )
SE for a test
√( p0(1−p0) / n )
Two proportions, CI
√( p̂1(1−p̂1)/n1 + p̂2(1−p̂2)/n2 )
Pooled, for a test
pool = (x1+x2) / (n1+n2)
Sample size
n ≥ p(1−p)(z*/ME)² — use p = 0.5, round up

Means

One sample / paired
SE = s/√n, df = n − 1
Two samples
SE = √( s1²/n1 + s2²/n2 )
Two-sample df, by hand
min(n1−1, n2−1)
ANOVA
F = MSG / MSE, df = k−1 and n−k
Bonferroni
α* = α / K, K = k(k−1)/2

2×2 tables

Risk
p1 = a/(a+b), p0 = c/(c+d)
Risk difference
RD = p1 − p0 (null = 0)
Relative risk
RR = p1 / p0 (null = 1)
Odds ratio
OR = ad / bc (null = 1)
SE(ln OR)
√( 1/a + 1/b + 1/c + 1/d )
SE(ln RR)
√( 1/a − 1/(a+b) + 1/c − 1/(c+d) )
CI for either
exp( ln(estimate) ± z* × SE(ln) )
Number needed to treat
NNT = 1 / |RD|, rounded up

Chi-square

Expected count
E = (row total × column total) / table total
Statistic
X² = Σ (O − E)² / E (upper tail only)
df, goodness of fit
k − 1
df, two-way
(R − 1)(C − 1)
Condition
every expected count ≥ 5

Regression

Model
ŷ = b0 + b1x
Slope
b1 = (sy/sx) R
Intercept
b0 = ȳ − b1x̄ (line passes through (x̄, ȳ))
Slope inference
t = b1/SE, df = n − 2
Multiple regression df
n − k − 1

Reference

Conditions to check first

Rubrics award marks for stating and checking these, separately from the arithmetic. It takes thirty seconds.

One proportion
Independence. Success–failure: ≥10 successes and ≥10 failures — checked with p̂ for an interval, p0 for a test.
Two proportions
Independence within and between groups. Success–failure in each group separately; use the pooled proportion when testing.
Chi-square
Independence — each case in exactly one cell. Every expected count at least 5; combine categories if one falls short.
One mean / paired
Independence. Normality: n < 30 needs no clear outliers; n ≥ 30 tolerates moderate skew. For paired data, check the differences.
Two means
Independence within and between. Normality checked separately in each group.
ANOVA
Independence always. Normality within groups — matters most when groups are small. Constant variance — matters most when group sizes differ.
Regression (LINE)
Linearity, Independent residuals, Nearly normal residuals, Equal variance. All four read off the residual plots.

Setup

R or SAS

R, unless the instructor’s document says otherwise. It is free, installs in about fifteen minutes, and OpenIntro publishes an R data package and R labs for this exact textbook — every figure in the book was made in R.

  1. Install R firstRStudio is only an editor and needs R underneath.
  2. Then RStudio DesktopFree. This is where the work actually happens.
  3. Install the book’s data packageIn RStudio: install.packages("openintro") then library(openintro)
  4. SAS, if requiredSAS OnDemand for Academics is free for students and runs in a browser. Approval is not instant — register early.
Deadline

The Software Verification assignment is due Friday Sept 11, four days into the term. Whichever package she picks, the schedule lists a software lesson every single week.

Resources

Worth bookmarking

Scope

In the textbook, not in the course

The schedule skips real parts of OpenIntro. Reading them is not wrong, but nothing here will be quizzed.

OIS 3.1–3.4
Probability rules, conditional probability, Bayes’ theorem, random variables. Only 3.5 is assigned. Week 2’s title does mention random variables, so expectation may appear in lecture.
OIS 4.2, 4.4, 4.5
Geometric, negative binomial and Poisson distributions. Only the normal and binomial are assigned.
OIS 6.2
Difference of two proportions — but the topic is covered, from EBPH 6.6 and 7.7 in weeks 10 and 11.
OIS 9.2.2, 9.2.3
Backward elimination, forward selection, and the p-value approach to model selection.
OIS 9.5
Logistic regression — explicitly excluded from week 14.

Still unknown

What the syllabus would settle

The course schedule is in hand; the detailed syllabus is not. These are the questions it would answer.