🎯 Objective: shuffle y against fixed x, m times ➔ refit ➔ the β^(i) form an empirical null distribution of no association ➔ p≈m+11+∑i=1mI(∣β^(i)∣≥∣β^∣).
📦 Core Components:H0:β=0 vs HA:β=0 | permutation keeps p(Y), breaks the pairing | +1 correction ➔ smallest p=1/(m+1).
⚡ Key Constraint: permute the targets only, without replacement — that is a shuffle; drawing with replacement is the bootstrap and does not simulate H0.
📝 How It Works
1. The Usual Test and Its Weak Point
Question ➔ n pairs (xi,yi): is y associated with x? In a linear model ⟹ test the slope, H0:β=0 vs HA:β=0.
Usual procedure ➔ specify a population distribution ➔ compute a statistic (the least-squares β^) ➔ see how likely it is under the derived null distribution.
Weak point ➔ the p-value depends crucially on the assumed distribution and on deriving the null accurately (often via the CLT).
2. The Algorithm
For i=1 to m ➔ randomly permute the targets ➔ compute the association statistic θ^(i).
Observed ➔ compute the statistic on the real data.
Compare ➔ how often the permutation distribution is at least as extreme ⟹ the p-value of association.
Key idea ➔ under no association the y values are exchangeable with respect to the predictors ⟹ permutations show how the estimate varies under the null.
+1 correction ➔ the finite-simulation estimate counts the observed data as one of the arrangements ⟹ p is never exactly 0; resolution 1/(m+1).
3. Strengths and Weaknesses
Strengths ➔ few assumptions about the population distribution · potentially more accurate p-values for non-normal models (logistic regression, etc.) · easy to code and apply.
Weaknesses ➔ resolution set by m (smallest p=1/(m+1)) · slow if each model fit is slow · assumes independent individuals.
4. Studio 10 — Permuting a Logistic Regression
Every coefficient at once ➔ shuffle the target column, refit the glm, store all coefficients ➔ one empirical null per coefficient; pj= share of permutations with ∣β^j(i)∣>∣β^j∣.
Which null is simulated ➔ permuting y breaks its link with every predictor together ⟹ the global null “target independent of all predictors”. The glm Wald p-values test βj=0given the other predictors, via an asymptotic normal ⟹ different hypotheses, so the two sets need not agree (Pima BP 0.0166 vs 0.004, AGE 0.070 vs 0.040, SKIN 0.374 vs 0.265).
What it avoids ➔ under an appropriate exchangeability null, no asymptotic approximation; cost ➔ R full model fits.
Monte Carlo noise ➔ at R=1000 reruns visibly move a smallish p (BP 0.008 in one run, 0.004 at R=10,000) ⟹ raise R until the decision stops changing.
Reading the null histogram ➔ INS: β^=0.00035 sits inside a null spanning ±0.002 ⟹ p≈0.75 · BP: β^=−0.017 lies beyond the null bulk ±0.01 ⟹ p≈0.004.
The zero floor in practice ➔ the studio’s perm.log.reg computes b/R and prints 0.0000 for PREG, PLAS, BMI — the +1 form of §2 would give ≤1/(R+1)≈0.0001.
🧮 Proof Blueprint
Theorem ➔ randomly permuting the observed y values against fixed x produces datasets distributed as under H0: no association.
Strategy ➔ factorise the joint, impose H0, then check which marginals a permutation preserves.
Derivation Steps:
p(Y,X)H0:p(Y∣X)permutation: =p(Y∣X)p(X)(always)=p(Y)⇒p(Y,X)=p(Y)p(X){yi} unchanged as a set⇒p(Y) kept;x untouched⇒p(X) kept;pairing random
Q.E.D. ➔ a permuted dataset is a draw from p(Y)p(X) — exactly the joint under H0 — so its statistics trace the null distribution with no normality assumption.
⚙️ Core Implementation
🔹 Permutation test for a regression slope
Code / Layout Details
# implements the lecture's algorithm (the slides give the procedure, not this code)bpfit = lm(BP ~ Age, data = bpdata); summary(bpfit) # beta.hat = 1.4310, t-test p = 0.00157beta.hat = coef(bpfit)[2]m = 10000; beta.perm = rep(0, m)for (i in 1:m) { y.perm = sample(bpdata$BP) # shuffle targets: NO replacement beta.perm[i] = coef(lm(y.perm ~ bpdata$Age))[2]}p = (1 + sum(abs(beta.perm) >= abs(beta.hat))) / (m + 1) # ≈ 0.0013hist(beta.perm, probability = TRUE) # the empirical null, centred on 0
💡 Common Mistake:sample(bpdata$BP, replace = TRUE) ➔ that is a bootstrap draw — values duplicate and vanish, so p(Y) is not preserved and the null is wrong.
📊 Exam Execution Trace & Applied Exercises
Manual Execution Trace
BP on Age, n=20 (Lecture 6 data); observed β^=1.4310, t-test p=0.00157:
Step
Data
β^(i)
∣β^(i)∣≥1.4310?
Running p=i+11+count
0
unpermuted
1.4310
—
—
1
permutation 1
−0.8418
no
1/2
2
permutation 2
−0.0253
no
1/3
3
permutation 3
0.3704
no
1/4
⋮
m=10,000
centred on 0, almost all within ±1.43
rare
≈0.0013
Reading ➔ after 3 permutations p cannot go below 1/4 — resolution, not evidence; at m=10,000 the permutation p≈0.0013 agrees closely with the normal-theory t-test’s 0.00157 ⟹ strong evidence BP is associated with Age.
Applied Exercise
Problem:m=999 permutations of a logistic-regression coefficient; 4 have ∣β^(i)∣≥∣β^∣. Find p. What if none did?
ppmin=999+11+4=10005=0.005=10001+0=0.001
Final Extracted Output:p=0.005 ⟹ strong evidence against H0; with no exceedances report p≤0.001 and raise m if a smaller p must be resolved.
⚠️ Common Mistakes
💡 Shuffling x and y together ➔ moving whole rows changes nothing; only one side is permuted to break the pairing.
💡 One-sided count for a two-sided test ➔ HA:β=0 needs absolute values on both sides of the comparison.
💡 Reporting p=0 ➔ with the +1 correction the floor is 1/(m+1).
💡 Ignoring dependence ➔ exchangeability needs independent individuals; clustered or time-ordered data break it.
🧠 Active Recall
Why does randomly permuting the targets generate data under H0 of no association?
Answer
Short answer: under H0 the joint factorises as p(Y)p(X); a permutation keeps the observed y values (so p(Y)) and the x values (so p(X)) but pairs them at random — a draw from that product.
Why:Exchangeability ➔ p(Y∣X)=p(Y) means the labels carry no information about x, so every reassignment is equally likely under H0.
The permutation test gives p≈0.0013 and the t-test 0.00157 for the same slope. Where does the difference come from, and when would it matter?
Answer
Short answer: the t-test’s null assumes normally distributed regression errors; the permutation null is built from the data with no such assumption (plus simulation noise from finite m). It matters for non-normal models, where the derived null may be inaccurate.
Why:Assumed vs simulated null ➔ both answer H0:β=0; only the route to the null distribution differs.
Studio 10's permutation p for BP is 0.004; summary(glm) says 0.0166. Which hypothesis does each test, and why can they differ?
Answer
Short answer: permuting the target simulates the global null (no predictor matters), compared coefficient by coefficient; the Wald test asks whether βBP=0given the other seven predictors, using a large-sample normal approximation.
Why:Different null, different route ➔ shuffling y also scrambles PLAS, BMI… so the null spread of β^BP is not the conditional one; and Wald p-values rely on asymptotics, permutation p-values on exchangeability plus finite-R noise.
Bootstrap or permutation test — which would you use to (a) give a CI for a slope, (b) give a p-value for "Age is unrelated to BP"?
Answer
Short answer: (a) bootstrap — rows with replacement, percentile CI; (b) permutation — shuffle BP against Age, count extremes.
Why:Variability vs null ➔ the bootstrap mimics repeated sampling from the real population; the permutation mimics sampling from a population where H0 holds.