| count_extreme | p_value | SE |
|---|---|---|
| 12 | 0.012 | 0.0796937 |
Permutation null distribution. Red = permuted differences at least as large as 0.2 (direction of H_A: >).
Math 215 — Inference with Simulation and Mathematical Models
Every chapter in this unit answers one of two questions about a population parameter:
Each question can be answered two ways:
| Simulation (computational) | Mathematical model (theoretical) | |
|---|---|---|
| p-value | Permutation test (or parametric bootstrap) builds the null distribution | Standardize the statistic (\(Z\), \(T\), \(X^2\), \(F\)) and find a tail area of a named distribution |
| CI | Bootstrap (percentile or SE method) | \(\text{point estimate} \pm \text{critical value} \times SE\) |
When the technical conditions are met, the simulation and theoretical approaches give very similar answers.
A mathematical model is only trustworthy when its conditions hold. If they fail, use simulation instead.
Independence (every test). Observations must be independent of one another. This is reasonable when data come from a simple random sample or a randomized experiment. With two or more groups, observations must be independent within and between groups (except paired data, where the pairs are independent of each other).
Large-sample / shape conditions (depend on the statistic):
| Method (Ch) | Distribution | Validity conditions |
|---|---|---|
| One proportion (16) | \(N(0,1)\) | Success-failure: test uses expected counts \(np_0 \geq 10\) and \(n(1-p_0) \geq 10\); CI uses observed counts \(n\hat p \geq 10\) and \(n(1-\hat p) \geq 10\) |
| Two proportions (17) | \(N(0,1)\) | At least 10 successes and 10 failures in each group (test: expected counts using \(\hat p_{pool}\); CI: observed counts) |
| Two-way table (18) | \(\chi^2_{(r-1)(c-1)}\) | At least 5 expected counts in every cell |
| One mean (19) | \(t_{n-1}\) | Normality: if \(n < 30\), no clear outliers (data look nearly normal); if \(n \geq 30\), no particularly extreme outliers |
| Two independent means (20) | \(t_{n_1+n_2-2}\) | Normality check in each group, and equal population variances for the pooled test (otherwise use the unequal-variance version) |
| Paired means (21) | \(t_{n_{diff}-1}\) | Normality check applied to the differences |
| Many means / ANOVA (22) | \(F_{k-1,\,n-k}\) | Nearly normal data within each group (no extreme outliers) and roughly equal variability across groups (most important when group sizes differ a lot) |
| Regression slope (24) | \(t_{n-2}\) | LINE: Linear relationship, Independent observations, Normal residuals, Equal (constant) variability of residuals; check with a scatterplot and residual plot |
Why these matter: the CLT says the statistic’s sampling distribution is approximately normal (or \(t\), \(\chi^2\), \(F\)) only when the sample is large enough and not dominated by skew or outliers. When a condition is violated, the theoretical tail area can be noticeably wrong.
R’s p functions (pnorm, pt, pchisq, pf) return the area to the left of a value. Use 1 - p...() for a right tail. For a two-sided test with a symmetric distribution (normal or \(t\)), double the area of one tail. The code for each worked example is in its chapter.
| Model | \(H_A\) direction | p-value | R code |
|---|---|---|---|
| Normal | \(>\) (right tail) | \(P(Z \geq z)\) | 1 - pnorm(z) |
| Normal | \(<\) (left tail) | \(P(Z \leq z)\) | pnorm(z) |
| Normal | \(\neq\) (two-sided) | \(2 \cdot P(Z \geq |z|)\) | 2 * pnorm(-abs(z)) |
| \(t\) | \(>\) (right tail) | \(P(T_{df} \geq t)\) | 1 - pt(t, df) |
| \(t\) | \(<\) (left tail) | \(P(T_{df} \leq t)\) | pt(t, df) |
| \(t\) | \(\neq\) (two-sided) | \(2 \cdot P(T_{df} \geq |t|)\) | 2 * pt(-abs(t), df) |
| \(\chi^2\) | always right tail | \(P(\chi^2_{df} \geq X^2)\) | 1 - pchisq(X2, df) |
| \(F\) | always right tail | \(P(F_{df_1, df_2} \geq F)\) | 1 - pf(F, df1, df2) |
Critical values for CIs come from the same distributions: \(z^* = 1.96\) for 95% (the 97.5th percentile of \(N(0,1)\)), and \(t^*_{df}\) is the 97.5th percentile of \(t_{df}\).
Outline
Key formulas
Problem. Does reminding students of the opportunity cost change their purchase decision? 150 students were randomly assigned: control (75) saw “buy / not buy this video”; treatment (75) also saw “keep the $14.99 for other purchases.” Success = “not buy video.”
Data: 34 of 75 treatment and 19 of 75 control students chose not to buy. \(\hat p_T - \hat p_C = \dfrac{34}{75} - \dfrac{19}{75} = 0.2\)
Hypotheses: \(H_0: p_T - p_C = 0\) (opportunity cost reminder has no effect) vs. \(H_A: p_T - p_C > 0\) (a higher proportion will not buy when reminded).
| count_extreme | p_value | SE |
|---|---|---|
| 12 | 0.012 | 0.0796937 |
Permutation null distribution. Red = permuted differences at least as large as 0.2 (direction of H_A: >).
The p-value is the proportion of permuted differences \(\geq 0.2\) (red bars): about 6 out of 1,000, so p-value ≈ 0.006. The SD of the null distribution gives \(SE \approx 0.0791\).
The conditions hold (random assignment; at least 10 successes and failures per group), so the null distribution is approximately \(N(0, 0.0791)\).
Computing probabilities from a normal model. For a density curve, the area under the curve is a probability. For example, under \(N(0, 0.0791)\), \(P(X \leq -0.03) = 0.352\) and \(P(X \geq -0.03) = 1 - 0.352 = 0.648\).
\[Z = \frac{(\hat p_T - \hat p_C) - 0}{SE} = \frac{0.2 - 0}{0.0791} = 2.528\]
Since \(H_A\) uses \(>\), the p-value is the right-tail area: \(P(Z \geq 2.528) \approx 0.006\), matching the simulation.
1 - pnorm(2.528) # right tail, H_A: p_T - p_C > 0[1] 0.005735718
Since \(Z = 2.528 > 1.96\), the observed value is outside the middle 95%, so the one-sided p-value is less than 0.025.
95% CI for \(p_T - p_C\): \[0.2 \pm 1.96 \times 0.0791 = 0.2 \pm 0.155 \Rightarrow (0.045, \ 0.355)\] 99% CI: \(0.2 \pm 2.576 \times 0.0791 = 0.2 \pm 0.203\). Higher confidence gives a wider interval (larger margin of error).
\(z^*\) is the cutoff with area \(1 - (1-C)/2\) to its left for a \(C\%\) CI: \(z^* = 1.645\) (90%), \(1.96\) (95%), \(2.576\) (99%).
Outline
Key formulas
Problem. Do blood thinners affect 24-hour survival of heart-attack patients who received CPR? Blood thinners can treat clots but may make CPR injuries harder to heal, so there is no expected direction. 90 patients randomly assigned (cpr, openintro): 40 treatment, 50 control. Success = “survived.”
Data: 14 of 40 treatment and 11 of 50 control patients survived. \(\hat p_T - \hat p_C = \dfrac{14}{40} - \dfrac{11}{50} = 0.13\)
Hypotheses (two-sided): \(H_0: p_T - p_C = 0\) vs. \(H_A: p_T - p_C \neq 0\)
Conditions are met, \(SE \approx 0.0955\) (details in Ch. 17), so the null distribution is \(N(0, 0.0955)\). “At least as extreme” now means \(\geq 0.13\) or \(\leq -0.13\).
\[Z = \frac{(\hat p_T - \hat p_C) - 0}{SE} = \frac{0.13 - 0}{0.0955} = 1.36\]
2 * pnorm(-abs(1.36)) # two-sided, H_A: p_T - p_C != 0[1] 0.1738299
The p-value is about 0.17 > \(\alpha = 0.05\), so we fail to reject \(H_0\); it is plausible survival rates are the same.
| \(H_0\) true | \(H_A\) true | |
|---|---|---|
| Reject \(H_0\) | Type 1 error (false alarm) | Correct decision (power) |
| Fail to reject \(H_0\) | Correct decision | Type 2 error (missed opportunity) |
Outline
Key formulas
Problem. Do a majority of Michigan payday borrowers support a new regulation requiring lenders to do a credit check? Let \(p\) = proportion of all MI payday borrowers who support it.
Data: random sample of \(n = 826\) borrowers; 424 support. \(\hat p = 424/826 = 0.513\)
Hypotheses: \(H_0: p = 0.5\) vs. \(H_A: p > 0.5\)
Conditions: random sample (independent); expected counts \(826 \times 0.5 = 413\) successes and 413 failures, both \(\geq 10\).
\[SE(\hat p) = \sqrt{\frac{p_0(1-p_0)}{n}} = \sqrt{\frac{0.5(1-0.5)}{826}} = 0.0174\] \[Z = \frac{\hat p - p_0}{SE(\hat p)} = \frac{0.513 - 0.5}{0.0174} = 0.765\]
1 - pnorm(0.765) # right tail, H_A: p > 0.5[1] 0.2221358
p-value ≈ 0.22, so we fail to reject \(H_0\); 50% is a plausible value. (We do not “accept” \(H_0\).)
95% CI (observed counts 424 and 402 are both \(\geq 10\)): \[SE \approx \sqrt{\frac{\hat p(1-\hat p)}{n}} = \sqrt{\frac{0.513(1-0.513)}{826}} = 0.0174\] \[0.513 \pm 1.96 \times 0.0174 = 0.513 \pm 0.034 \Rightarrow (0.479, \ 0.547)\]
The CI contains 0.5, consistent with the test.
Outline
Key formulas
Problem. Do blood thinners affect survival of CPR patients? (cpr; 40 treatment, 50 control, randomly assigned.)
| group | died | survived | total |
|---|---|---|---|
| control | 39 | 11 | 50 |
| treatment | 26 | 14 | 40 |
| total | 65 | 25 | 90 |
\(\hat p_T - \hat p_C = \dfrac{14}{40} - \dfrac{11}{50} = 0.13\)
Hypotheses: \(H_0: p_T - p_C = 0\) vs. \(H_A: p_T - p_C \neq 0\)
| count_extreme | p_value |
|---|---|
| 245 | 0.245 |
Permutation null distribution for the CPR study. Red = permuted differences at least as extreme as the observed 0.13 in either direction (H_A: ≠).
The p-value is the proportion of permuted differences \(\geq 0.13\) or \(\leq -0.13\) (red bars): about 0.17.
Pooled proportion: \(\hat p_{pool} = \dfrac{25}{90} = 0.278\).
Conditions: randomized experiment (independent); expected successes \(40(0.278) = 11.1\) and \(50(0.278) = 13.9\); expected failures \(28.9\) and \(36.1\). All \(\geq 10\).
\[SE = \sqrt{\hat p_{pool}(1-\hat p_{pool})\left(\frac{1}{n_1}+\frac{1}{n_2}\right)} = \sqrt{0.278(0.722)\left(\frac{1}{40} + \frac{1}{50}\right)} = 0.095\] \[Z = \frac{(\hat p_T - \hat p_C) - 0}{SE} = \frac{0.13 - 0}{0.095} = 1.37\]
2 * pnorm(-abs(1.37)) # two-sided, H_A: p_T - p_C != 0[1] 0.1706869
p-value ≈ 0.171, close to the permutation p-value because the success-failure condition holds. Fail to reject \(H_0\).
Bootstrap: resample with replacement within each group (40 from treatment, 50 from control) and compute the difference each time.
| lower_ci | upper_ci |
|---|---|
| -0.0543478 | 0.3107413 |
Bootstrap distribution of the difference in survival rates, centered near 0.13. Shaded = 95% percentile CI.
| SE_boot |
|---|
| 0.094442 |
Bootstrap distribution of the difference in survival rates, centered near 0.13. Shaded = 95% percentile CI.
Normal approximation (observed counts 14, 26, 11, 39 all \(\geq 10\)): \[SE \approx \sqrt{\frac{\hat p_T(1-\hat p_T)}{n_T}+\frac{\hat p_C(1-\hat p_C)}{n_C}} = \sqrt{\frac{0.35(0.65)}{40}+\frac{0.22(0.78)}{50}} = 0.0955\] \[0.13 \pm 1.96 \times 0.0955 \Rightarrow (-0.057, \ 0.317)\]
| Method | 95% CI |
|---|---|
| Bootstrap percentile | (−0.055, 0.313) |
| Bootstrap SE (\(0.13 \pm 1.96 \times 0.0944\)) | (−0.055, 0.315) |
| Normal approximation (\(0.13 \pm 1.96 \times 0.0955\)) | (−0.057, 0.317) |
All intervals contain 0, consistent with failing to reject \(H_0\).
Outline
Key formulas
Problem. Do people of different U.S. political parties have different views on government spending on national defense? 2016 General Social Survey, 149 respondents; party (Dem/Ind/Rep) vs. natarms (too little / about right / too much).
Hypotheses: \(H_0\): party and opinion on military spending are independent (no association). \(H_A\): party and opinion are associated.
Observed counts with expected counts in parentheses:
| Party | TOO LITTLE | ABOUT RIGHT | TOO MUCH | Total |
|---|---|---|---|---|
| Dem | 17 (17.60) | 14 (14.43) | 12 (10.97) | 43 |
| Ind | 20 (29.48) | 28 (24.16) | 24 (18.36) | 72 |
| Rep | 24 (13.92) | 8 (11.41) | 2 (8.67) | 34 |
| Total | 61 | 50 | 38 | 149 |
Example: \(E_{\text{Dem, too little}} = \dfrac{43 \times 61}{149} = 17.60\).
\[X^2 = \sum \frac{(O - E)^2}{E} = \frac{(17-17.60)^2}{17.60} + \cdots + \frac{(2-8.67)^2}{8.67}\] \[X^2 = 0.02 + 0.01 + 0.10 + 3.05 + 0.61 + 1.73 + 7.30 + 1.02 + 5.13 = 18.97\]
TOO LITTLE ABOUT RIGHT TOO MUCH
Dem 17.60 14.43 10.97
Ind 29.48 24.16 18.36
Rep 13.92 11.41 8.67
X-squared
18.96998
Shuffle the opinions across respondents and recompute \(X^2\) each time.
| count_extreme | p_value |
|---|---|
| 0 | 0 |
Permutation null distribution of X². Red = shuffled X² at least as large as 18.97 (right tail); there are none.
No shuffled \(X^2\) values are \(\geq 18.97\), so the p-value ≈ 0. The null distribution is right-skewed and never negative.
Conditions: representative random sample (independent); all expected counts \(\geq 5\). \(df = (r-1)(c-1) = (3-1)(3-1) = 4\).
1 - pchisq(18.97, df = 4) # right tail of chi-squared, df = 4[1] 0.0007966825
p-value < 0.001: reject \(H_0\). Strong evidence that opinion on military spending and party are associated. Representative sample → can generalize; observational → no cause-and-effect.
Outline
Key formulas
Problem. The mean finishing time in 2006 was 93.29 minutes. Has the mean finishing time changed in 2017? Let \(\mu\) = mean 2017 finish time.
Data: random sample of \(n = 100\) runners from 2017 (run17, cherryblossom). \(\bar x = 99.02\) min, \(s = 17.93\) min.
Hypotheses: \(H_0: \mu = 93.29\) vs. \(H_A: \mu \neq 93.29\)
| lower_ci | upper_ci |
|---|---|
| 95.53098 | 102.5462 |
1,000 bootstrap sample means. Shaded = 95% percentile CI. Their spread (SE ≈ 1.8) is much smaller than the spread of the raw data (s ≈ 17.9).
| SE_boot |
|---|
| 1.776952 |
1,000 bootstrap sample means. Shaded = 95% percentile CI. Their spread (SE ≈ 1.8) is much smaller than the spread of the raw data (s ≈ 17.9).
Bootstrap SE CI: \(\bar x \pm 1.96 \times SE_{boot} = 99.02 \pm 1.96(1.78) = (95.51, \ 102.49)\).
For a single mean there are no groups to shuffle, so the data are shifted to have mean 93.29 (making \(H_0\) true) and then bootstrapped.
| count_extreme | p_value |
|---|---|
| 1 | 0.001 |
Null distribution centered at 93.29. Red = simulated means at least as far from 93.29 as the observed 99.02, in either direction (H_A: ≠).
Conditions: random sample (independent); \(n = 100 \geq 30\) with no particularly extreme outliers.
\[T = \frac{\bar x - \mu_0}{s/\sqrt n} = \frac{99.02 - 93.29}{17.93/\sqrt{100}} = \frac{5.73}{1.793} = 3.20, \qquad df = 100 - 1 = 99\]
2 * pt(-abs(3.20), df = 99) # two-sided, H_A: mu != 93.29[1] 0.001847065
p-value ≈ 0.002 < 0.05: reject \(H_0\). The 2017 mean finish time differs from 93.29 (it is higher; runners got slower).
\[\bar x \pm t^*_{99} \times \frac{s}{\sqrt n} = 99.02 \pm 1.98 \times \frac{17.93}{\sqrt{100}} \Rightarrow (95.46, \ 102.56)\]
| Method | 95% CI |
|---|---|
| One-sample \(t\)-interval | (95.46, 102.56) |
| Bootstrap SE | (95.51, 102.49) |
| Bootstrap percentile | (95.53, 102.55) |
93.29 is outside every interval, consistent with rejecting \(H_0\) at \(\alpha = 0.05\).
Outline
Key formulas
Problem. Do babies of mothers who smoke have a different mean birth weight than babies of mothers who don’t? Let \(\mu_n\) and \(\mu_s\) be mean birth weights (lb) for nonsmoking and smoking mothers.
Data: random sample of 981 U.S. births in 2014 (births14).
| habit | \(n\) | mean | sd |
|---|---|---|---|
| nonsmoker | 867 | 7.27 | 1.23 |
| smoker | 114 | 6.68 | 1.60 |
\(\bar x_n - \bar x_s = 7.27 - 6.68 = 0.59\) lb
Hypotheses: \(H_0: \mu_n - \mu_s = 0\) vs. \(H_A: \mu_n - \mu_s \neq 0\)
| count_extreme | p_value |
|---|---|
| 0 | 0 |
Permutation null distribution of the difference in means. Red = permuted differences at least as extreme as ±0.59 (H_A: ≠); none are, so nothing is shaded.
No permuted differences are as extreme as 0.59, so the p-value ≈ 0.
Conditions: random sample (independent within and between groups); large samples with no extreme outliers; SDs 1.23 and 1.60 are reasonably similar.
\[s_p = \sqrt{\frac{(n_n-1)s_n^2 + (n_s-1)s_s^2}{n_n+n_s-2}} = \sqrt{\frac{866(1.23^2) + 113(1.60^2)}{979}} = 1.28\] \[T = \frac{(\bar x_n - \bar x_s) - 0}{s_p\sqrt{\frac{1}{n_n}+\frac{1}{n_s}}} = \frac{0.59}{1.28\sqrt{\frac{1}{867} + \frac{1}{114}}} = 4.63, \qquad df = 867 + 114 - 2 = 979\]
2 * pt(-abs(4.63), df = 979) # two-sided, H_A: mu_n - mu_s != 0[1] 4.148965e-06
p-value < 0.001: reject \(H_0\). Strong evidence that mean birth weights differ.
| lower_ci | upper_ci |
|---|---|
| 0.3106516 | 0.8989899 |
Bootstrap distribution of the difference in means (resampling within each group). Shaded = 95% percentile CI, which does not contain 0.
\(t\)-interval: \[SE = s_p\sqrt{\frac{1}{n_n}+\frac{1}{n_s}} = 1.28\sqrt{\frac{1}{867} + \frac{1}{114}} = 0.128\] \[0.59 \pm t^*_{979} \times 0.128 = 0.59 \pm 1.96(0.128) \Rightarrow (0.339, \ 0.841)\]
Bootstrap percentile ≈ (0.31, 0.92). Zero is not in either interval, consistent with the test.
Outline
Key formulas
\[\bar x_{diff} = \text{mean of the differences}, \qquad SE_{diff} = \frac{s_{diff}}{\sqrt{n_{diff}}}\] \[T = \frac{\bar x_{diff} - 0}{s_{diff}/\sqrt{n_{diff}}}, \qquad df = n_{diff} - 1\] \[\text{CI: } \bar x_{diff} \pm t^*_{df} \times SE_{diff}\]
Problem. Do you save money buying textbooks on Amazon instead of the UCLA bookstore? Each book has two prices, so the data are paired. Difference = UCLA bookstore price − Amazon price. Let \(\mu_{diff}\) = mean price difference.
Data: 68 books (ucla_textbooks_f18). \(\bar x_{diff} = 3.58\), \(s_{diff} = 13.4\), median 0.625.
Hypotheses: \(H_0: \mu_{diff} = 0\) vs. \(H_A: \mu_{diff} \neq 0\)
Under \(H_0\) the “UCLA” and “Amazon” labels are interchangeable within a book. Each permutation flips a coin for each book: keep the prices, or swap them (which flips the sign of that book’s difference).
| count_extreme | p_value |
|---|---|
| 17 | 0.017 |
Null distribution of the mean difference from 1,000 within-pair permutations. Red = means at least as extreme as ±3.58 (H_A: ≠).
The p-value is the proportion of permuted means \(\geq 3.58\) or \(\leq -3.58\) (red bars).
Resample the 68 differences with replacement.
| lower_ci | upper_ci |
|---|---|
| 0.4706287 | 6.934684 |
Bootstrap distribution of the mean price difference. Shaded = 95% percentile CI.
| SE_boot |
|---|
| 1.658731 |
Bootstrap distribution of the mean price difference. Shaded = 95% percentile CI.
Percentile CI ≈ ($0.81, $7.05); bootstrap SE CI: \(3.58 \pm 1.96(1.63) \approx\) ($0.39, $6.77).
Conditions: books are independent of each other; \(n_{diff} = 68 \geq 30\), and although the differences are skewed, there are no particularly extreme outliers.
\[SE_{diff} = \frac{s_{diff}}{\sqrt{n_{diff}}} = \frac{13.4}{\sqrt{68}} = 1.62\] \[T = \frac{\bar x_{diff} - 0}{SE_{diff}} = \frac{3.58 - 0}{1.62} = 2.20, \qquad df = 68 - 1 = 67\]
2 * pt(-abs(2.20), df = 67) # two-sided, H_A: mu_diff != 0[1] 0.03125996
p-value ≈ 0.031 < 0.05: reject \(H_0\); on average, UCLA bookstore prices are higher than Amazon’s.
95% CI: \(\bar x_{diff} \pm t^*_{67} \times SE_{diff} = 3.58 \pm 1.996(1.62) \Rightarrow (\$0.35, \ \$6.81)\), which excludes 0.
Outline
Key formulas (\(k\) groups, \(n\) total observations)
| Quantity | Formula |
|---|---|
| Mean squares | \(MSG = \dfrac{SSG}{k-1}, \quad MSE = \dfrac{SSE}{n-k}\) |
| F statistic | \(F = \dfrac{MSG}{MSE} = \dfrac{\text{variability between groups}}{\text{variability within groups}}\) |
Model: \(F \sim F_{k-1, \, n-k}\) if observations are independent, data are nearly normal within groups (no extreme outliers), and variances are roughly equal. The p-value is always the right tail (large \(F\) = group means far apart relative to within-group spread).
Outline
Key formulas
(No notes file for this chapter was in the folder.) Use this decision guide for numerical responses:
| Situation | Statistic | Simulation | Mathematical model |
|---|---|---|---|
| One sample of numbers | \(\bar x\) | Bootstrap (CI), shifted bootstrap (test) | \(t_{n-1}\) |
| Two independent groups | \(\bar x_1 - \bar x_2\) | Permute group labels (test), bootstrap within groups (CI) | \(t_{n_1 + n_2 - 2}\) (pooled) |
| Two measurements on the same unit | \(\bar x_{diff}\) | Permute within pairs / sign flips (test), bootstrap differences (CI) | \(t_{n_{diff}-1}\) |
| Three or more groups | \(F\) | Permute group labels (test) | \(F_{k-1,\,n-k}\) |
Ask: Is the data paired? How many groups? Are conditions (independence, normality/outliers, equal variance) reasonable?
Outline
Key formulas
bdims (openintro): body measurements of 507 physically active adults. Population line: \(\widehat{\text{Weight}} = -105.01 + 1.02 \times \text{Height}\).
bdims)Problem. Is body weight linearly associated with height? Data: 507 adults (bdims). Let \(\beta_1\) = population slope of weight (kg) on height (cm).
Hypotheses: \(H_0: \beta_1 = 0\) vs. \(H_A: \beta_1 \neq 0\)
From the least squares fit, \(b_1 \approx 1.02\) kg per cm. The test statistic is \(T = \dfrac{b_1 - 0}{SE_{b_1}}\) with \(df = 507 - 2 = 505\), and the p-value is the two-sided tail area of \(t_{505}\).
2 * pt(-abs(T), df = 505) # two-sided, H_A: beta_1 != 0[1] 2.8291e-81
Shuffle the response (\(y\)) values to break any link with \(x\), then refit the line.
| count_extreme | p_value |
|---|---|
| 0 | 0 |
Null distribution of slopes from 1,000 shuffles of weight. Red = slopes at least as extreme as the observed slope in either direction; none are, so the p-value ≈ 0.
Resample (x, y) pairs with replacement and refit.
| lower_ci | upper_ci |
|---|---|
| 0.9380495 | 1.101884 |
Bootstrap distribution of the slope. Shaded = 95% percentile CI.
| Ch | Parameter | Standard error | Test statistic/Standardized Score/CI |
|---|---|---|---|
| 16 | \(p\) | Test: \(\sqrt{p_0(1-p_0)/n}\); CI: \(\sqrt{\hat p(1-\hat p)/n}\) | Statistic: \(\hat p\) Standardized: \(Z = \dfrac{\hat p - p_0}{\sqrt{p_0(1-p_0)/n}}\) CI: \(\hat p \pm z^* \sqrt{\dfrac{\hat p(1-\hat p)}{n}}\) |
| 17 | \(p_1 - p_2\) | Test: \(\sqrt{\hat p_{pool}(1-\hat p_{pool})(\frac{1}{n_1}+\frac{1}{n_2})}\); CI: unpooled | Statistic: \(\hat p_1 - \hat p_2\) Standardized: \(Z = \dfrac{(\hat p_1 - \hat p_2) - 0}{\sqrt{\hat p_{pool}(1-\hat p_{pool})\left(\frac{1}{n_1}+\frac{1}{n_2}\right)}}\) CI: \((\hat p_1 - \hat p_2) \pm z^* \sqrt{\dfrac{\hat p_1(1-\hat p_1)}{n_1}+\dfrac{\hat p_2(1-\hat p_2)}{n_2}}\) |
| 18 | association | — | \(df = (r-1)(c-1)\) Statistic: \(X^2 = \sum \dfrac{(O-E)^2}{E}\), with \(E = \dfrac{\text{row total} \times \text{col total}}{\text{table total}}\) Standardized: — CI: — |
| 19 | \(\mu\) | \(s/\sqrt n\) | \(df = n - 1\) Statistic: \(\bar x\) Standardized: \(T = \dfrac{\bar x - \mu_0}{s/\sqrt n}\) CI: \(\bar x \pm t^*_{df} \dfrac{s}{\sqrt n}\) |
| 20 | \(\mu_1 - \mu_2\) | \(s_p\sqrt{\frac{1}{n_1}+\frac{1}{n_2}}\), \(s_p = \sqrt{\frac{(n_1-1)s_1^2 + (n_2-1)s_2^2}{df}}\) | \(df = n_1 + n_2 - 2\) Statistic: \(\bar x_1 - \bar x_2\) Standardized: \(T = \dfrac{(\bar x_1 - \bar x_2) - 0}{s_p\sqrt{\frac{1}{n_1}+\frac{1}{n_2}}}\) CI: \((\bar x_1 - \bar x_2) \pm t^*_{df}\, s_p\sqrt{\dfrac{1}{n_1}+\dfrac{1}{n_2}}\) |
| 21 | \(\mu_{diff}\) | \(s_{diff}/\sqrt{n_{diff}}\) | \(df = n_{diff} - 1\) Statistic: \(\bar x_{diff}\) Standardized: \(T = \dfrac{\bar x_{diff} - 0}{s_{diff}/\sqrt{n_{diff}}}\) CI: \(\bar x_{diff} \pm t^*_{df} \dfrac{s_{diff}}{\sqrt{n_{diff}}}\) |
| 22 | all \(\mu_i\) equal | — | \(df_G = k - 1\), \(df_E = n - k\) Statistic: \(F = \dfrac{MSG}{MSE}\), with \(MSG = \dfrac{SSG}{df_G}\), \(MSE = \dfrac{SSE}{df_E}\) Standardized: — CI: — (pairwise CIs via Tukey or Bonferroni) |
| 24 | \(\beta_1\) | \(SE_{b_1} = \dfrac{s}{\sqrt{\sum(x_i - \bar x)^2}}\) | \(df = n - 2\) Statistic: \(b_1\) Standardized: \(T = \dfrac{b_1 - 0}{SE_{b_1}}\) CI: \(b_1 \pm t^*_{df}\, SE_{b_1}\) |
Multiple comparisons (after ANOVA or a \(\chi^2\) test): \(m = k(k-1)/2\) pairs; \(P(\text{at least one Type 1 error}) = 1-(1-\alpha)^m\); Bonferroni level \(\alpha/m\) (adjusted p-value \(= m \times\) p-value); Bonferroni CI level \(100(1-\alpha/m)\%\); Tukey CIs excluding 0 indicate significant differences.
Simulation methods:
| Goal | Simulation | Centered at |
|---|---|---|
| Test, one proportion | Draw samples from a population with \(p = p_0\) (parametric bootstrap) | \(p_0\) |
| Test, one mean | Shift data to mean \(\mu_0\), then bootstrap | \(\mu_0\) |
| Test, two groups / two-way table / ANOVA / slope | Permute (shuffle) the response | null value |
| Test, paired | Permute within pairs (flip signs of differences) | 0 |
| CI (any) | Bootstrap (resample with replacement) | observed statistic |
Simulated p-value: count the simulated statistics as extreme as or more extreme than the observed statistic in the direction of \(H_A\), divided by the number of simulations (shown in red in the pictures). Bootstrap CI: middle 95% of bootstrap statistics (percentile method) or \(\text{estimate} \pm 1.96 \times SE_{boot}\) (SE method).