Lecture 4
Simple Linear Regression: Prediction
This lecture estimates the mean response at a given \(x_0\), gives a confidence interval for it, and gives a prediction interval for a new response (Lecture 4 · p.1–43).
Unit 01Recap: the model, the estimators, and inference for \(\beta_1\)
Model (p.3), estimators (p.4), CI (p.5), test (p.6), brainhead results (p.7).
Small data set: \(x=(1,2,3,4,5)\), \(y=(2,4,5,4,5)\), \(n=5\).
Brainhead data: \(y\) is brain weight (g). \(x\) is head size (cm³).
01.1Title page and section page Slides p.1–2
01.2The model and its assumptions Slides p.3
What Slides p.3
1. Linearity
2. Independence
3. Normality
4. Equal variance (homoskedasticity)
\(E[y_i]=\beta_0+\beta_1x_i\).
The errors \(\epsilon_i\) are independent.
Each \(\epsilon_i\) has a normal distribution.
Each \(\epsilon_i\) has variance \(\sigma^2\), at all \(x_i\).
How Added
- Find the response \(y\): the variable to explain or predict.
- Find the covariate \(x\): the variable that explains \(y\).
- Count the observations to get \(n\).
- Write \(y_i=\beta_0+\beta_1x_i+\epsilon_i\), \(\epsilon_i\overset{iid}{\sim}N(0,\sigma^2)\), \(i=1,\dots,n\).
- Write \(y_i\overset{indep}{\sim}N(\beta_0+\beta_1x_i,\sigma^2)\). List the four assumptions.
Self-check: \(\beta_0\), \(\beta_1\), \(\sigma^2\) are unknown. The data give \(x_i\), \(y_i\), \(n\).
Example 1 · The small data set Added
Pairs: \((1,2),(2,4),(3,5),(4,4),(5,5)\).
Example 2 · The brainhead data Slides p.7
Why · The two forms are equal Added
01.3The least squares estimators and the distribution of \(\hat\beta_1\) Slides p.4
What Slides p.4
Putting \(\hat\sigma\) for the unknown \(\sigma\) changes \(N(0,1)\) to \(t_{n-2}\).
How Added
- Calculate \(\bar x\) and \(\bar y\).
- Calculate \(S_{xx}\) and \(S_{xy}\).
- Calculate \(\hat\beta_1=S_{xy}/S_{xx}\).
- Calculate \(\hat\beta_0=\bar y-\hat\beta_1\bar x\).
- Calculate each fitted value \(\hat y_i\) and each residual \(e_i\).
- Calculate \(\hat\sigma^2=\sum e_i^2/(n-2)\) and \(\hat\sigma\).
- Calculate \(\mathrm{SE}(\hat\beta_1)=\hat\sigma/\sqrt{S_{xx}}\).
Self-check: The residuals add to 0. The line contains \((\bar x,\bar y)\).
Example 3 · The small data set Added
Self-check: \(-0.8+0.6+1.0-0.6-0.2=0\), and \(2.2+0.6\times3=4=\bar y\). With \(n-2=3\):
\[\frac{\hat\beta_1-\beta_1}{\hat\sigma/\sqrt{S_{xx}}}=\frac{0.6-\beta_1}{0.282843}\sim t_{3}.\]Example 4 · The brainhead data Slides p.7
Each 1 cm³ more head size increases the estimated mean brain weight by 0.26082 g.
\[\frac{\hat\beta_1-\beta_1}{\hat\sigma/\sqrt{S_{xx}}}=\frac{0.26082-\beta_1}{0.01307}\sim t_{234}.\]Why · The distribution chain Added
01.4The confidence interval for \(\beta_1\) Slides p.5
What Slides p.5
or \(\hat\beta_1\pm t_{0.975,n-2}\times \mathrm{SE}(\hat\beta_1)\).
If we were to collect a new sample, we would obtain a different estimate and a different 95% CI
- 95% of such intervals will cover the true \(\beta_1\)
How Added
- Get \(\hat\beta_1\) and \(\mathrm{SE}(\hat\beta_1)\).
- Calculate the degrees of freedom \(n-2\).
- Find \(t_{1-\alpha/2,n-2}\) in a \(t\) table or with software.
- Calculate the half-width \(t_{1-\alpha/2,n-2}\times\mathrm{SE}(\hat\beta_1)\).
- Calculate \(\hat\beta_1-\text{half-width}\) and \(\hat\beta_1+\text{half-width}\).
Self-check: The midpoint is \(\hat\beta_1\). A higher confidence level gives a wider interval.
Example 5 · 95% CI for the small data set Added
The 95% CI is \([-0.300132,\ 1.500132]\). It is wide because \(n=5\) is small and \(t_{0.975,3}\) is large.
Example 6 · 95% CI for the brainhead data Slides p.7
Slides p.7 prints \([0.2350725,\ 0.2865689]\) (more input digits). We are 95% confident that 1 cm³ more head size increases the mean brain weight by 0.2351 g to 0.2866 g.
Why · The interval formula Added
Let \(q=t_{0.975,n-2}\) and \(T\sim t_{n-2}\).
In line 5, \(\hat\beta_1\) and \(\hat\sigma\) are random; \(\beta_1\) is fixed. 0.95 is the probability that the interval covers \(\beta_1\).
01.5The hypothesis test for \(\beta_1\) Slides p.6
What Slides p.6
Under \(H_0\): \(\dfrac{\hat\beta_1-\theta_0}{\hat\sigma/\sqrt{S_{xx}}}\sim t_{n-2}\)
- P-value: What's the probability under the null of observing a test statistic as or more extreme than the one we observed?
- I.e. for \(T\sim t_{n-2}\) and our observed test statistic \(t^{obs}\): \(P(|T|\ge|t^{obs}|)\)
How Added
- Write \(H_0\) and \(H_1\). Find \(\theta_0\).
- Get \(\hat\beta_1\) and \(\mathrm{SE}(\hat\beta_1)\).
- Calculate \(t^{obs}=(\hat\beta_1-\theta_0)/\mathrm{SE}(\hat\beta_1)\).
- Calculate the p-value \(2P(T\ge|t^{obs}|)\), with \(T\sim t_{n-2}\).
- Compare the p-value with the significance level \(\alpha\), usually 0.05.
- If the p-value < \(\alpha\), reject \(H_0\). If not, do not reject it.
Self-check: For \(\theta_0=0\), the 95% CI excludes 0 exactly when the p-value < 0.05.
Example 7 · Test \(H_0:\beta_1=0\) for the small data set Added
The 95% CI of Example 5, \([-0.300132,\ 1.500132]\), also contains 0.
Example 8 · Test \(H_0:\beta_1=0\) for the brainhead data Slides p.7
Head size and brain weight have a linear relation. The 95% CI \([0.2351,\ 0.2866]\) also excludes 0.
Why · The test statistic has the \(t_{n-2}\) distribution Added
01.6The brainhead results on Slides p.7 Slides p.7
What Slides p.7
Later lectures explain the numbers below.
How Added
- Match each estimate to \(\hat\beta_0\) or \(\hat\beta_1\).
- Match the slope standard error to \(\mathrm{SE}(\hat\beta_1)=\hat\sigma/\sqrt{S_{xx}}\).
- Divide each estimate by its standard error: \(t^{obs}\) for \(\theta_0=0\).
- Match each p-value to \(P(|T|\ge|t^{obs}|)\), \(T\sim t_{n-2}\).
- Add 2 to the degrees of freedom: \(n\).
- Compare the midpoint of each CI with the estimate.
Self-check: Each \(t\) value is the estimate divided by its standard error.
Example 9 · Check each number Slides p.7
01.7Practice Added
Q1. From Slides p.7, calculate a 90% CI for \(\beta_1\). Use \(t_{0.95,234}=1.651391\). Interpret it.
Answer
The 90% CI is \([0.239236,\ 0.282404]\). We are 90% confident that 1 cm³ more head size increases the mean brain weight by 0.2392 g to 0.2824 g. It is narrower than the 95% CI because 1.651391 < 1.970154.
Q2. Test \(H_0:\beta_1=0.25\) vs \(H_1:\beta_1\neq0.25\) at the 5% level. Report \(t^{obs}\), the p-value, and your conclusion.
Answer
The 95% CI \([0.2351,\ 0.2866]\) also contains 0.25.
Q3. Verify the 95% CI for \(\beta_0\) on Slides p.7. Use \(t_{0.975,234}=1.970154\).
Answer
This agrees with \([241.3053884,\ 429.5592416]\) on Slides p.7.
Unit 02Point estimate of the mean response and its distribution
\(\hat\mu_0\) and its second form (p.10–13), \(E[\hat\mu_0]\) (p.14–15), \(\mathrm{Var}[\hat\mu_0]\) (p.16–17), distribution (p.18).
Slides p.8 Page 8 repeats the Lecture 4 title page.
Slides p.9 Page 9 is the section page "Estimating Mean Response".
Model: \(y_i=\beta_0+\beta_1x_i+\epsilon_i\), \(\epsilon_i\overset{iid}{\sim}N(0,\sigma^2)\), or \(y_i\overset{indep}{\sim}N(\beta_0+\beta_1x_i,\sigma^2)\).
Estimators: \(\hat\beta_1=S_{xy}/S_{xx}\), \(\hat\beta_0=\bar y-\hat\beta_1\bar x\), with \(S_{xx}=\sum_{i=1}^n(x_i-\bar x)^2\), \(S_{xy}=\sum_{i=1}^n(y_i-\bar y)(x_i-\bar x)\).
An estimator is random. An estimate is its number for one data set.
Brainhead data: \(n=236\) persons, \(x_i\) head size (cm³), \(y_i\) brain weight (g).
Slides p.7: \(\hat\beta_0=335.43231\), \(\hat\beta_1=0.26082\), \(\hat\sigma=72.35\), \(n-2=234\).
From brainhead.csv (Added): \(\bar x=3637.864\), \(\bar y=1284.263\), \(S_{xx}=30647233.66\), \(\hat\beta_1=0.2608207\).
02.1The mean response \(\mu_0\) and its point estimate \(\hat\mu_0\) Slides p.10–13
What Slides p.10
For an arbitrary \(x_0\), the mean outcome is \(\mu_0:=E[y_0\mid x_0]=\beta_0+\beta_1x_0\).
We can estimate this as \[\hat\mu_0=\hat\beta_0+\hat\beta_1x_0\]
The conditional expectation \(E[y\mid x]\) is the long-run average of \(y\) at one fixed \(x\).
The mean response \(E[y\mid x]\) is the height \(\beta_0+\beta_1x\) of the true line, because \(E[\epsilon]=0\).
\(x_0\) is a covariate value of interest, not necessarily in the data. \(y_0\) is the response at \(x_0\).
The symbol \(:=\) means "is defined as".
A point estimate is one number that estimates an unknown quantity. \(\hat\mu_0\) is the point estimate of \(\mu_0\).
\(\mu_0\) is unknown, because \(\beta_0\) and \(\beta_1\) are unknown. \(\hat\mu_0\), the height of the fitted line at \(x_0\), comes from the data.
• What happens at \(\bar x\)?
The second form starts at the center \((\bar x,\bar y)\). It moves along the fitted line by \(x_0-\bar x\), with height change \(\hat\beta_1\) per unit.
At \(x_0=\bar x\) (Slides p.13), the distance is 0, and \(\hat\mu_0=\bar y\).
How Added
- Calculate \(n\), \(\bar x\), \(\bar y\), \(S_{xx}\) and \(S_{xy}\).
- Calculate \(\hat\beta_1=S_{xy}/S_{xx}\) and \(\hat\beta_0=\bar y-\hat\beta_1\bar x\).
- Form 1 (Slides p.10): put \(x_0\) into \(\hat\mu_0=\hat\beta_0+\hat\beta_1x_0\).
- Form 2 (Slides p.12): calculate \(x_0-\bar x\).
- Calculate \(\bar y+\hat\beta_1(x_0-\bar x)\).
Self-check: ① Both forms agree, to rounding. ② At \(x_0=\bar x\), the result is \(\bar y\). ③ If \(\hat\beta_1>0\) and \(x_0>\bar x\), the result is above \(\bar y\).
Example 1 · The brainhead data at \(x_0=4000\) cm³ Added
Start values How step 1
From brainhead.csv (Added).
Coefficients How step 2
Basis: Slides p.4. Slides p.7 prints 335.43231 and 0.26082.
Form 1 How step 3 · Slides p.10
Form 2 How steps 4–5 · Slides p.12
Self-check: Both forms give 1378.715, above \(\bar y=1284.263\) (check ③).
At \(x_0=\bar x\) Slides p.13
At 4000 cm³, the estimated mean brain weight is \(\hat\mu_0=1378.715\) g. At \(x_0=\bar x\), it is \(\bar y=1284.263\) g.
Why · The two forms are equal Slides p.10–13
Definition, Slides p.10.
Slides p.4, p.11.
Slides p.12. ∎
At \(x_0=\bar x\) (Slides p.13):
The fitted line contains \((\bar x,\bar y)\). ∎
02.2\(\hat\mu_0\) is unbiased Slides p.14–15
What Slides p.15
An estimator is unbiased when its expectation equals the parameter it estimates. \(E[\hat\mu_0]=\mu_0\).
Repeated sampling: keep \(x_1,\dots,x_n\), get new \(y_1,\dots,y_n\), and calculate \(\hat\mu_0\) again.
One \(\hat\mu_0\) can be too high or too low. On average over repeated samples, it is correct.
How Added
- Write \(\hat\mu_0=\hat\beta_0+\hat\beta_1x_0\).
- Use linearity of expectation: \(E[aU+bV]=aE[U]+bE[V]\) for constants \(a\), \(b\).
- Treat \(x_0\) as a constant.
- Put in \(E[\hat\beta_0]=\beta_0\) and \(E[\hat\beta_1]=\beta_1\) (Lecture 3).
Self-check: The result has no hat. It is \(\beta_0+\beta_1x_0=\mu_0\).
Example 2 · A small data set with known parameters Added
Real data have unknown \(\beta_0\), \(\beta_1\). This example sets them: \(n=3\), \(x=(1,2,3)\), \(\beta_0=2\), \(\beta_1=0.5\), \(x_0=4\).
Write \(\hat\mu_0=\sum_{i=1}^n c_iy_i\), with weight \(c_i=\frac1n+\frac{(x_i-\bar x)(x_0-\bar x)}{S_{xx}}\) (Section 02.3, line 6).
Center and spread of \(x\)
Weights \(c_i\)
Expected responses
\(E[y_i]=\beta_0+\beta_1x_i\) (Slides p.3).
Expectation of \(\hat\mu_0\)
True mean response
Self-check: \(E[\hat\mu_0]=4=\mu_0\).
Why · \(\hat\mu_0\) is unbiased Slides p.14–15
Slides p.10.
Linearity of expectation.
\(x_0\) is a constant.
Lecture 3.
Slides p.10. ∎
02.3The variance of \(\hat\mu_0\) Slides p.16–17
What Slides p.17
The denominator is \(S_{xx}\).
The first term, \(\sigma^2/n\), does not change with \(x_0\).
The second term, \(\sigma^2(x_0-\bar x)^2/S_{xx}\), increases as \(x_0\) moves away from \(\bar x\).
The variance is smallest, \(\sigma^2/n\), at \(x_0=\bar x\). Away from the center, the distance multiplies the error in \(\hat\beta_1\).
How Added
- Calculate \(1/n\).
- Calculate \((x_0-\bar x)^2/S_{xx}\).
- Add them to get the factor \(\frac1n+\frac{(x_0-\bar x)^2}{S_{xx}}\).
- Multiply the factor by \(\sigma^2\).
- For a number, use \(\hat\sigma\) for \(\sigma\) and take the square root.
Self-check: ① The factor is at least \(1/n\). ② At \(x_0=\bar x\), it is \(1/n\). ③ Equal distances from \(\bar x\) give equal variances.
Slides p.7 prints \(\hat\sigma=72.35\).
Example 3 · The brainhead data at \(x_0=4000\) and \(x_0=\bar x\) Added
\(x_0=4000\): the two terms How steps 1–2
\(x_0=4000\): the factor How step 3
\(x_0=4000\): multiply by \(\sigma^2\) How steps 4–5
\(x_0=\bar x\)
Self-check: 4.710 < 6.677. The estimate is most precise at the center.
Example 4 · The small data set of Example 2 Added
Calculate \(\mathrm{Var}[\hat\mu_0]\) in two ways for \(x=(1,2,3)\), \(x_0=4\).
Formula from Slides p.17
Sum of squared weights
Line 7 below: \(\mathrm{Var}[\hat\mu_0]=\sigma^2\sum c_i^2\).
Self-check: Both give \(\mathrm{Var}[\hat\mu_0]=\frac73\sigma^2\).
Why · The chain for the variance Slides p.16–17
The chain follows Slides p.17, with one change per line.
Fact A (model): \(y_1,\dots,y_n\) are independent, and \(\mathrm{Var}[y_i]=\sigma^2\).
Fact B (Lecture 2): \(\mathrm{Var}(aY)=a^2\mathrm{Var}(Y)\). For independent \(X\) and \(Y\), \(\mathrm{Var}(X+Y)=\mathrm{Var}(X)+\mathrm{Var}(Y)\).
Fact C: \(\sum_{i=1}^n(x_i-\bar x)=\sum_{i=1}^n x_i-n\bar x=n\bar x-n\bar x=0\).
Fact D (Lecture 3): \(\hat\beta_1=\sum_{i=1}^n w_iy_i\), with fixed \(w_i=\frac{x_i-\bar x}{S_{xx}}\).
Slides p.10.
Put in \(\hat\beta_0\).
As in Section 02.1.
Put in \(\bar y=\sum_{i=1}^n\frac1n y_i\). (Added: split.)
Fact D.
Join the two sums.
Facts A and B. (Added: split.)
Fact A.
\((a+b)^2=a^2+b^2+2ab\).
Split into three sums.
\(\sum_{i=1}^n\frac1{n^2}=n\cdot\frac1{n^2}=\frac1n\). (Added: split.)
Move the constant out. (Added: split.)
Definition of \(S_{xx}\). (Added: split.)
Move the constant out. Second-last line, Slides p.17.
Fact C. (Added: split.)
\(S_{xx}/S_{xx}^2=1/S_{xx}\). (Added: split.)
Last line, Slides p.17. ∎
Number check (Added): the three sums of line 10 for \(x=(1,2,3)\), \(x_0=4\), \(\bar x=2\), \(S_{xx}=2\), \(x_0-\bar x=2\).
First: \(\sum_{i=1}^3\frac1{3^2}=3\times\frac19=\frac13\).
Second: \(\frac{(1)(4)+(0)(4)+(1)(4)}{2^2}=\frac{8}{4}=2\), equal to \((x_0-\bar x)^2/S_{xx}=4/2=2\).
Third: \(2\times\frac13\times\frac{(-1)(2)+(0)(2)+(1)(2)}{2}=2\times\frac13\times\frac{0}{2}=0\).
Total: \(\frac13+2+0=\frac73\), as in Example 4.
02.4The distribution of \(\hat\mu_0\) Slides p.18
What Slides p.18
The symbol \(\sim\) means "has the distribution".
A linear combination is \(\sum_{i=1}^n c_iy_i\) with fixed numbers \(c_i\).
How Added
- Family: \(\hat\mu_0\) is a linear combination of independent normal \(y_i\). It is normal.
- Mean: \(E[\hat\mu_0]=\mu_0=\beta_0+\beta_1x_0\) (Section 02.2).
- Variance: \(\sigma^2\left(\frac1n+\frac{(x_0-\bar x)^2}{S_{xx}}\right)\) (Section 02.3).
- Put in \(n\), \(\bar x\), \(S_{xx}\) and \(x_0\).
Self-check: The mean has no hat. The only unknown in the variance is \(\sigma^2\).
Example 5 · The brainhead data at \(x_0=4000\) Added
Family How step 1
Fixed weights, independent normal \(y_i\): normal.
Mean How step 2
Variance How steps 3–4
Factor 0.008516375: Example 3. Data value: \(\hat\mu_0=1378.715\).
Why · \(\hat\mu_0\) is normal (the "why?" on Slides p.18) Slides p.18
Section 02.3, line 6. Each weight uses only \(n\), \(x_i\), \(\bar x\), \(x_0\), \(S_{xx}\): a fixed number.
Slides p.3.
Same rule as for \(\hat\beta_1=\sum w_iy_i\) (Lecture 3).
Section 02.2 (Slides p.15).
Variance: Section 02.3 (Slides p.17). ∎
02.5Practice Added
Q1. Brainhead data: \(n=236\), \(\bar x=3637.864\), \(\bar y=1284.263\), \(\hat\beta_0=335.4323\), \(\hat\beta_1=0.2608207\). Calculate \(\hat\mu_0\) at \(x_0=3000\) cm³ in two ways: (a) \(\hat\beta_0+\hat\beta_1x_0\); (b) \(\bar y+\hat\beta_1(x_0-\bar x)\).
Answer
(a) \(0.2608207\times3000=782.4621\). \(\hat\mu_0=335.4323+782.4621=1117.894\).
(b) \(x_0-\bar x=3000-3637.864=-637.864\).
\(\hat\beta_1(x_0-\bar x)=0.2608207\times(-637.864)=-166.368\).
\(\hat\mu_0=1284.263-166.368=1117.895\). This agrees with (a) to rounding (1117.894).
\(x_0<\bar x\) and \(\hat\beta_1>0\): the result is below \(\bar y\).
Q2. Show that \(\mathrm{Var}[\hat\mu_0]\) is smallest at \(x_0=\bar x\). Give its value there in terms of \(\sigma^2\) and \(n\).
Answer
\(\mathrm{Var}[\hat\mu_0]=\sigma^2\left(\frac1n+\frac{(x_0-\bar x)^2}{S_{xx}}\right)\).
\(\sigma^2/n\) does not change with \(x_0\). \((x_0-\bar x)^2\geq0\) and \(S_{xx}>0\). The second term is 0 only at \(x_0=\bar x\), and positive elsewhere.
At \(x_0=\bar x\):
\[\mathrm{Var}[\hat\mu_0]=\sigma^2\left(\frac1n+\frac{(\bar x-\bar x)^2}{S_{xx}}\right)=\sigma^2\left(\frac1n+0\right)=\frac{\sigma^2}{n}\]
There \(\hat\mu_0=\bar y\), and \(\mathrm{Var}[\bar y]=\sigma^2/n\) agrees.
Q3. Brainhead data, \(S_{xx}=30647233.66\). Calculate \(\frac1n+\frac{(x_0-\bar x)^2}{S_{xx}}\) at \(x_0=3000\) and \(x_0=4500\). Where is the estimate of \(\mu_0\) more precise? Use the distance to \(\bar x\).
Answer
\(x_0=3000\): \(x_0-\bar x=-637.8644\), \((x_0-\bar x)^2=406871.0\), \(406871.0/30647233.66=0.01327595\). Factor: \(0.004237288+0.01327595=0.01751323\).
\(x_0=4500\): \(x_0-\bar x=862.1356\), \((x_0-\bar x)^2=743277.8\), \(743277.8/30647233.66=0.02425269\). Factor: \(0.004237288+0.02425269=0.02848998\).
0.01751323 < 0.02848998: the estimate is more precise at \(x_0=3000\).
3000 is 637.9 from \(\bar x\); 4500 is 862.1 from \(\bar x\). The variance increases with \((x_0-\bar x)^2\).
Unit 03Confidence interval for the mean response
Brainhead data, \(n=236\). Slides p.7: \(\hat\beta_0=335.43231\), \(\hat\beta_1=0.26082\), \(\hat\sigma=72.35\) on 234 degrees of freedom.
More digits from brainhead.csv (Added): \(\hat\beta_0=335.432315\), \(\hat\beta_1=0.2608207153\), \(\hat\sigma=72.35066237\), \(\bar x=3637.864407\), \(S_{xx}=30647233.66\).
Start result (Slides p.18):
\[\hat\mu_0\sim N\!\left(\mu_0,\ \sigma^2\left(\frac1n+\frac{(x_0-\bar x)^2}{\sum_{i=1}^n(x_i-\bar x)^2}\right)\right)\]03.1Standardize: from \(N(0,1)\) to \(t_{n-2}\) Slides p.19
What Slides p.19
To standardize a normal quantity, subtract its mean and divide by its standard deviation.
The first line contains the unknown \(\sigma\). We cannot calculate it from data.
The second line uses \(\hat\sigma\) for \(\sigma\). This changes \(N(0,1)\) to \(t_{n-2}\).
\(\mathrm{SE}(\hat\mu_0)=\hat\sigma\sqrt{\frac1n+\frac{(x_0-\bar x)^2}{S_{xx}}}\) estimates the standard deviation of \(\hat\mu_0\).
How Added
- Calculate \(n\), \(\bar x\) and \(S_{xx}\).
- Calculate \(\hat\beta_0\), \(\hat\beta_1\), the residuals \(e_i\) and \(\hat\sigma\).
- Calculate \((x_0-\bar x)^2\).
- Divide by \(S_{xx}\).
- Add \(1/n\).
- Take the square root.
- Multiply by \(\hat\sigma\).
Self-check: ① The unit of SE is the unit of \(y\) (g). ② The step 5 sum is much less than 1. SE must be much less than \(\hat\sigma\).
Example 1 · Standard error at \(x_0=4000\) Added
Steps 1–2 come from the start point.
Distance from \(\bar x\) How step 3
Divide by \(S_{xx}\) How step 4
Add \(1/n\) How step 5
Square root How step 6
Multiply by \(\hat\sigma\) How step 7
6.676823721 g is much less than \(\hat\sigma=72.35066237\) g. ▲
Why Added
Same logic as Lecture 3 p.31 for \(\hat\beta_1\). Let \(c_0=\frac1n+\frac{(x_0-\bar x)^2}{S_{xx}}\).
Slides p.18.
First line of Slides p.19.
Lecture 3 p.31: \(Z\), \(V\) independent.
Lecture 3 p.31.
Second line of Slides p.19. ∎
Two random quantities are independent when the value of one gives no information about the other.
03.2The \(100(1-\alpha)\%\) confidence interval for \(\mu_0\) Slides p.20
What Slides p.20
With repeated samples, \(100(1-\alpha)\%\) of these intervals contain the true \(\mu_0\).
The interval is "center ± quantile × standard error", with center \(\hat\mu_0\).
The half-width is \(t_{1-\alpha/2,\,n-2}\times\mathrm{SE}(\hat\mu_0)\).
How Added
- Calculate \(\mathrm{SE}(\hat\mu_0)\) (Section 03.1).
- Calculate the center \(\hat\mu_0=\hat\beta_0+\hat\beta_1x_0\).
- Find the quantile \(t_{1-\alpha/2,\,n-2}\).
- Multiply the quantile by \(\mathrm{SE}(\hat\mu_0)\) to get the half-width.
- Lower limit \(L\): \(\hat\mu_0\) minus the half-width.
- Upper limit \(U\): \(\hat\mu_0\) plus the half-width.
Self-check: ① \((L+U)/2=\hat\mu_0\). ② At 95% with \(n=236\), the quantile is 1.970, near 1.96.
Example 2 · 95% CI for the mean brain weight at \(x_0=4000\) Added
Example 1 gives \(\mathrm{SE}(\hat\mu_0)=6.676823721\) (How step 1).
Center How step 2
Quantile How step 3
Half-width How step 4
Basis: Example 1.
Lower limit How step 5
Upper limit How step 6
Self-check: \((1365.560808+1391.869545)/2=1378.715176=\hat\mu_0\).
At head size 4000 cm³, the 95% CI for the mean brain weight is (1365.561, 1391.870) g. ▲
Why Added
Isolate \(\mu_0\). Let \(t=t_{1-\alpha/2,\,n-2}\) and \(\mathrm{SE}=\hat\sigma\sqrt{\frac1n+\frac{(x_0-\bar x)^2}{S_{xx}}}\).
Section 03.1; symmetric, each tail \(\alpha/2\).
\(\mathrm{SE}>0\).
Multiply by \(-1\); the signs change direction.
∎
03.3Confidence intervals at a range of \(x_0\) values Slides p.21–22
What Slides p.21–22
Slides p.21 shows only code. It does Section 03.2 at many \(x_0\).
A grid is a list of values with equal spaces. The \(x_0\) grid goes from the smallest to the largest \(x\), step 1.
All intervals are 95% and use \(t_{0.975,\,234}\).
Slides p.22 plots the data, the fitted line, and \(L\) and \(U\) at each grid value.
A confidence band is the pair of curves through all \(L\) and all \(U\).
How Added
- Find the smallest and the largest \(x\).
- Make the grid of \(x_0\) values between them, step 1.
- At each grid value, calculate \(L\) and \(U\) (Section 03.2).
- Plot the data and the fitted line \(\hat\beta_0+\hat\beta_1x\).
- Join all lower limits with a curve.
- Join all upper limits with a second curve.
Self-check: ① Grid size = (largest \(x\) − smallest \(x\)) + 1. ② At \(x_0=4000\), the limits are (1365.561, 1391.870), as in Example 2.
Example 3 · The first grid value Added
Brainhead data (Added): smallest \(x\) is 2773, largest \(x\) is 4747.
Number of grid values How step 2
Distance from \(\bar x\) 03.1 How steps 3–4
Standard error 03.1 How steps 5–7
Center 03.2 How step 2
Half-width 03.2 How step 4
Limits 03.2 How steps 5–6
First band points: (2773, 1034.564) and (2773, 1082.813). The other 1974 grid values give the full band in Figure 3-1. ▲
03.4Why the intervals become wider toward the edges Slides p.23
What Slides p.23
Half-width: \(t_{1-\alpha/2,\,n-2}\,\hat\sigma\sqrt{\frac1n+\frac{(x_0-\bar x)^2}{S_{xx}}}\).
Only \((x_0-\bar x)^2\) changes with \(x_0\). All other parts are fixed for one data set.
This term increases as \(x_0\) moves from \(\bar x\). It is 0 at \(\bar x\), where the interval is narrowest.
How Added
- For each \(x_0\), calculate \(|x_0-\bar x|\).
- Calculate the half-width (Section 03.2).
- Multiply it by 2 to get the width.
- Sort the \(x_0\) values by \(|x_0-\bar x|\).
- Make sure that the widths increase in the same order.
Self-check: ① At \(x_0=\bar x\), \(\mathrm{SE}(\hat\mu_0)=\hat\sigma/\sqrt n\). ② The ratio of two widths depends only on the two sums under the square root.
Example 4 · Widths at four values of \(x_0\) Added
All use \(t_{0.975,\,234}=1.970153643\), \(\hat\sigma=72.35066237\), \(1/n=0.004237288136\), \(S_{xx}=30647233.66\).
\(\frac{(x_0-\bar x)^2}{S_{xx}}=0\). Sum \(=0.004237288136\). Square root \(=0.06509445549\).
\(\mathrm{SE}(\hat\mu_0)=72.35066237\times0.06509445549=4.709626971\). Half-width \(=1.970153643\times4.709626971=9.278688732\).
\(\hat\mu_0=335.432315+948.8303969=1284.262712\). CI \(=(1274.984,\ 1293.541)\). Width \(=2\times9.278688732=18.557\).
Self-check: \(\hat\sigma/\sqrt n=72.35066237\times0.06509445549=4.709626971=\mathrm{SE}(\hat\mu_0)\).
From Examples 1–2: \(\mathrm{SE}(\hat\mu_0)=6.676823721\). Half-width \(=13.15436858\).
CI \(=(1365.561,\ 1391.870)\). Width \(=2\times13.15436858=26.309\).
From Example 3: \(\mathrm{SE}(\hat\mu_0)=12.24496152\). Half-width \(=24.12445554\).
CI \(=(1034.564,\ 1082.813)\). Width \(=2\times24.12445554=48.249\).
\(\frac{(x_0-\bar x)^2}{S_{xx}}=\frac{1230181.764}{30647233.66}=0.0401400589\). Sum \(=0.04437734703\). Square root \(=0.2106593151\).
\(\mathrm{SE}(\hat\mu_0)=72.35066237\times0.2106593151=15.24134098\). Half-width \(=1.970153643\times15.24134098=30.02778345\).
\(\hat\mu_0=335.432315+1238.115936=1573.548251\). CI \(=(1543.520,\ 1603.576)\). Width \(=2\times30.02778345=60.056\).
Widths in order of \(|x_0-\bar x|\): 18.557, 26.309, 48.249, 60.056. The width at the largest \(x\) is \(\sqrt{0.04437734703/0.004237288136}=3.236209805\) times the width at \(\bar x\). ▲
Why Added
The structure of the Slides p.17 result:
\[\mathrm{Var}[\hat\mu_0]=\mathrm{Var}[\bar y+\hat\beta_1(x_0-\bar x)]=\underbrace{\frac{\sigma^2}{n}}_{\text{from }\bar y}+\underbrace{\frac{\sigma^2(x_0-\bar x)^2}{S_{xx}}}_{\text{from }\hat\beta_1}\]The first equal sign uses Slides p.12. The second is Slides p.17, where the cross term is 0 because \(\sum_{i=1}^n(x_i-\bar x)=0\). ∎
The error in \(\bar y\) is the same at each \(x_0\). It gives \(\frac1n\). The distance \(x_0-\bar x\) multiplies the slope error. It gives \(\frac{(x_0-\bar x)^2}{S_{xx}}\).
03.5Why most points are outside the lines Slides p.24
What Slides p.24
The interval targets the mean \(\mu_0\), not one observation.
Each observation is \(y_i=\mu_i+\epsilon_i\), with \(\mu_i=\beta_0+\beta_1x_i\).
\(\epsilon_i\) has standard deviation \(\sigma\), estimated by \(\hat\sigma=72.35066237\) g.
The largest half-width of the band is 30.02778345 g, at \(x_0=4747\) (Example 4).
Most observations are farther from the line than this half-width.
How Added
- Use \(x_i\) as \(x_0\).
- Calculate \(L_i\) and \(U_i\) (Section 03.2).
- Compare \(y_i\) with \(L_i\) and \(U_i\).
- If \(L_i\le y_i\le U_i\), the point is inside. If not, it is outside.
- Do steps 1–4 for all \(n\) observations. Count the two groups.
Self-check: inside + outside \(=n=236\).
Example 5 · Two persons of the brainhead data Added
Person 1: \(x_1=4512\), \(y_1=1530\). Person 2: \(x_2=3738\), \(y_2=1297\).
Person 1: standard error How steps 1–2
Person 1: limits How step 2
Person 1: compare How steps 3–4
Inside.
Person 2: standard error How steps 1–2
Person 2: limits How step 2
Person 2: compare How steps 3–4
Outside: residual \(1297-1310.380149=-13.38014892\) g exceeds half-width 9.630252153 g.
All 236 persons: 41 inside, 195 outside (data file, Added). \(195/236=0.8262711864\), or 82.6%. Self-check: \(41+195=236\). ▲
Why Added
Compare the variance of one observation with the variance of \(\hat\mu_0\).
Slides p.3.
Slides p.17.
Example 4: largest at \(x_0=4747\).
Less than 5% of \(\mathrm{Var}[y_i]\). ∎
The interval shows only the error of \(\hat\mu_0\). As \(n\) increases, the interval becomes narrower. The spread \(\sigma\) of each point does not decrease with \(n\).
03.6When we want to predict a new observation Slides p.25
With exact \(\beta_0\), \(\beta_1\), \(\hat\mu_0=\mu_0\) has no estimation error.
A new observation is still \(\mu_0+\epsilon\), with \(\epsilon\sim N(0,\sigma^2)\) and \(\hat\sigma=72.35066237\) g.
An interval for a new observation must include the error of the mean estimate and the new error \(\epsilon\).
A prediction interval is an interval made to contain a new observation (Unit 04).
CI for \(\mu_0\): \(\hat\mu_0\pm t_{1-\alpha/2,\,n-2}\,\hat\sigma\sqrt{\frac1n+\frac{(x_0-\bar x)^2}{\sum_{i=1}^n(x_i-\bar x)^2}}\). Narrowest at \(\bar x\). It contains the mean, not single observations.
03.7Practice Added
Given: \(n=236\), \(\bar x=3637.864407\), \(S_{xx}=30647233.66\), \(\hat\beta_0=335.432315\), \(\hat\beta_1=0.2608207153\), \(\hat\sigma=72.35066237\).
Q1. Calculate a 90% CI for the mean brain weight at \(x_0=4000\) cm³. Use \(t_{0.95,\,234}=1.651391475\). Give the half-width and the interval.
Answer
Examples 1–2.
It is narrower than the 95% interval (1365.561, 1391.870), because 1.651391475 < 1.970153643.
Q2. Calculate the 95% CI for the mean response at \(x_0=3500\). First predict: wider or narrower than at \(x_0=4000\)? Then compare with your numbers.
Answer
Prediction: \(|3500-\bar x|=137.8644068\) < \(|4000-\bar x|=362.1355932\). The interval is narrower.
Width \(2\times9.934529096=19.869\) < 26.309 at \(x_0=4000\). This agrees with the prediction.
Q3. At which \(x_0\) is the CI for \(\mu_0\) narrowest? How many times wider is the 95% interval at \(x_0=4747\)? Why does this ratio not depend on \(\hat\sigma\) or \(\alpha\)?
Answer
Narrowest at \(x_0=\bar x=3637.864407\), where \((x_0-\bar x)^2=0\).
Example 4: \(60.0555669/18.55737746=3.236209805\).
\(2t_{1-\alpha/2,\,n-2}\hat\sigma\) cancels. The ratio depends only on \(x_0\), \(n\) and \(S_{xx}\).
Unit 04Predicting a new response: the prediction interval
Brainhead data, \(n=236\). Slides p.7: \(\hat\beta_0=335.43231\), \(\hat\beta_1=0.26082\), \(\hat\sigma=72.35\), \(n-2=234\).
From brainhead.csv (Added): \(\hat\beta_0=335.432315\), \(\hat\beta_1=0.2608207153\), \(\hat\sigma=72.35066237\), \(\bar x=3637.864407\), \(S_{xx}=30647233.66\).
All examples use \(x_{new}=4000\), as in Units 02–03.
04.1The new response and the predicted value Slides p.26–30
What Slides p.27–30
• But we'll need to take into account additional uncertainty (why?)
\(x_{new}\) is the fixed covariate value of the new observation.
The new response \(y_{new}\) is the unobserved response of the new observation. It is random because of its error \(\epsilon_{new}\).
The new error \(\epsilon_{new}\sim N(0,\sigma^2)\) is independent of \(\epsilon_1,\dots,\epsilon_n\).
The predicted value \(\hat y_{new}\) is the fitted line at \(x_{new}\), our guess for \(y_{new}\).
Slide question 1: how does this differ from the estimate of the mean? With \(x_0=x_{new}\), the formulas are the same: \(\hat y_{new}=\hat\mu_0\). The target is different:
\(\mu_0=\beta_0+\beta_1x_0\) is a fixed parameter, with no error term.
\(y_{new}=\beta_0+\beta_1x_{new}+\epsilon_{new}\) has the random error \(\epsilon_{new}\).
Slide question 2: why is there additional uncertainty? Uncertainty is the possible difference between a guess and the true value. A new response has two sources:
Source 1: \(\hat\beta_0+\hat\beta_1x_{new}\) changes from sample to sample, as for the mean.
Source 2: \(\epsilon_{new}\). We cannot guess it, even with the true \(\beta_0\) and \(\beta_1\).
How Added
- Get \(\hat\beta_1=S_{xy}/S_{xx}\) and \(\hat\beta_0=\bar y-\hat\beta_1\bar x\).
- Multiply \(\hat\beta_1\) by \(x_{new}\).
- Add \(\hat\beta_0\).
Self-check: \(\hat y_{new}=\hat\mu_0\) at the same \(x\).
Example 1 · The brainhead data at \(x_{new}=4000\) Added How steps 2–3
Predict the brain weight of a new person with head size 4000 cm³.
Compare with unit 02: \(\hat\mu_0=1378.715\) is the same number. In this unit, it predicts one person. In unit 02, it estimates the mean of all persons with head size 4000. ▲
04.2Expectation and variance of the prediction error Slides p.31–35
What Slides p.31–35
Properties: \[E[\hat y_{new}-y_{new}]=E[(\hat\beta_0+\hat\beta_1x_{new})-(\beta_0+\beta_1x_{new}+\epsilon_{new})]=\beta_0+\beta_1x_{new}-(\beta_0+\beta_1x_{new})=0\] Now note that \(\hat y_{new}\) and \(y_{new}\) are independent (why?) \[\mathrm{Var}[\hat y_{new}-y_{new}]=\sigma^2\left(1+\frac1n+\frac{(x_{new}-\bar x)^2}{\sum_{i=1}^n(x_i-\bar x)^2}\right)\]
The prediction error \(\hat y_{new}-y_{new}\) is the predicted value minus the true new response. It is random.
Expectation 0: on average, \(\hat y_{new}\) is not too high and not too low.
The term \(\sigma^2\left(\frac1n+\frac{(x_{new}-\bar x)^2}{S_{xx}}\right)\) is source 1. It equals \(\mathrm{Var}[\hat\mu_0]\) of unit 02.
The term \(\sigma^2\) is source 2, from \(\epsilon_{new}\).
Independence: \(\hat y_{new}\) uses only \(y_1,\dots,y_n\). The random part of \(y_{new}\) is \(\epsilon_{new}\), independent of the sample.
How Added
- Calculate \(\frac1n\).
- Calculate \((x_{new}-\bar x)^2/S_{xx}\).
- Multiply the sum of steps 1–2 by \(\hat\sigma^2\): the line part (source 1).
- The new-error part (source 2) is \(\hat\sigma^2\).
- Add the two parts: \(\hat\sigma^2\left(1+\frac1n+\frac{(x_{new}-\bar x)^2}{S_{xx}}\right)\).
Self-check: Step 3 equals the estimate of \(\mathrm{Var}[\hat\mu_0]\) in unit 02. The total is larger than \(\hat\sigma^2\).
Example 2 · The brainhead data at \(x_{new}=4000\) Added How steps 1–5
Use \(\hat\sigma\) for \(\sigma\): \(\hat\sigma^2=72.35066237^2=5234.618345\).
Result: \(\epsilon_{new}\) gives almost all of the variance. This term does not decrease as \(n\) increases. The prediction interval is much wider than the confidence interval. ▲
Why · The expectation and the variance of the prediction error Slides p.33–35
(a) Expectation. Use \(E[\hat\beta_0]=\beta_0\), \(E[\hat\beta_1]=\beta_1\), \(E[\epsilon_{new}]=0\).
(b) Independence.
\(\hat\beta_0\) and \(\hat\beta_1\) use only \(y_1,\dots,y_n\), whose random part is \(\epsilon_1,\dots,\epsilon_n\).
The random part of \(y_{new}\) is \(\epsilon_{new}\), independent of \(\epsilon_1,\dots,\epsilon_n\).
\(\hat y_{new}\) and \(y_{new}\) are independent.
(c) Variance.
For independent \(A\) and \(B\): \(\mathrm{Var}[A-B]=\mathrm{Var}[A]+\mathrm{Var}[B]\).
Unit 02 (Lecture 4 · p.17–18): \(\mathrm{Var}[\hat\beta_0+\hat\beta_1x_0]=\sigma^2\left(\frac1n+\frac{(x_0-\bar x)^2}{\sum_{i=1}^n(x_i-\bar x)^2}\right)\).
\(\mathrm{Var}[y_{new}]=\mathrm{Var}[\epsilon_{new}]=\sigma^2\).
\(\epsilon_{new}\) adds the "1", compared with \(\mathrm{Var}[\hat\mu_0]\). ∎
04.3The prediction interval Slides p.36–37
What Slides p.36–37
A prediction interval (PI) is an interval, calculated from the data, that contains the random \(y_{new}\) with probability \(1-\alpha\).
The confidence interval (CI) of unit 03 contains the fixed \(\mu_0\) with probability \(1-\alpha\).
The only difference from the CI is the "1" under the square root: the \(\sigma^2\) from \(\epsilon_{new}\).
How Added
- Calculate \(\hat y_{new}=\hat\beta_0+\hat\beta_1x_{new}\) (Section 04.1).
- Calculate \(1+\frac1n+\frac{(x_{new}-\bar x)^2}{S_{xx}}\).
- Take the square root and multiply by \(\hat\sigma\): the standard error of prediction.
- Find the quantile \(t_{1-\alpha/2,\,n-2}\).
- Multiply step 4 by step 3: the half-width.
- Subtract the half-width from \(\hat y_{new}\) and add it to \(\hat y_{new}\).
Self-check: ① The midpoint is \(\hat y_{new}\). ② The standard error of prediction is larger than \(\hat\sigma\). ③ The PI is wider than the CI at the same point.
Example 3 · The brainhead data at \(x_{new}=4000\), 95% prediction interval Added How steps 1–6
Find the 95% PI for the brain weight of a new person with head size 4000 cm³. Compare it with the 95% CI for the mean. \(\alpha=0.05\), \(n-2=234\).
Basis: Example 1.
Basis: Example 2, step 1.
95% CI for \(\mu_0\) (unit 03, Example 2): \((1365.561,\ 1391.870)\), width \(2\times13.154=26.31\) g.
95% PI for \(y_{new}\): \((1235.568,\ 1521.863)\), width \(2\times143.148=286.30\) g.
Same midpoint, 1378.715. The PI is \(143.1476/13.15437=10.88\) times as wide.
Slides p.39 shows both bands over a range of \(x\) (Unit 05). ▲
Why · From the distribution to the prediction interval Slides p.36–37
Let \(k=1+\frac1n+\frac{(x_{new}-\bar x)^2}{\sum_{i=1}^n(x_i-\bar x)^2}\).
Normality: \(\hat y_{new}\) is a linear combination of the normal \(y_1,\dots,y_n\).
\(y_{new}\) is normal and independent of the sample. A linear combination of independent normals is normal.
Line 8: this random interval contains the random \(y_{new}\) with probability \(1-\alpha\). ∎
04.4Practice Added
Given: \(n=236\), \(\bar x=3637.864407\), \(S_{xx}=30647233.66\), \(\hat\beta_0=335.432315\), \(\hat\beta_1=0.2608207153\), \(\hat\sigma=72.35066237\).
Q1. A new person has head size 4000 cm³. Calculate a 90% PI for this person's brain weight. Use \(t_{0.95,\,234}=1.651391\).
Answer
Step 1: \(\hat y_{new}=1378.715176\) (Example 1).
Steps 2–3: \(\hat\sigma\sqrt{1+\frac1n+\frac{(x_{new}-\bar x)^2}{S_{xx}}}=72.658092\) (Example 3).
Step 4: \(\alpha=0.10\), \(t_{1-0.10/2,\,234}=t_{0.95,\,234}=1.651391\).
Step 5: half-width \(=1.651391\times72.658092=119.9870\).
Step 6: \(1378.715\pm119.987=(1258.728,\ 1498.702)\).
It is narrower than the 95% PI \((1235.568,\ 1521.863)\), because its quantile is smaller.
Q2. Calculate a 95% PI for the brain weight of a new person with head size 4500 cm³. Use \(t_{0.975,\,234}=1.970154\).
Answer
Step 1: \(\hat y_{new}=335.432315+0.2608207153\times4500=335.432315+1173.693219=1509.125534\).
Step 2: \(x_{new}-\bar x=4500-3637.864407=862.135593\). \(\frac{862.135593^2}{30647233.66}=\frac{743277.7807}{30647233.66}=0.024252688\).
\(1+\frac1{236}+0.024252688=1+0.004237288+0.024252688=1.028489976\).
Step 3: \(\hat\sigma\sqrt{1.028489976}=72.35066237\times1.014144948=73.374059\).
Step 4: \(t_{0.975,\,234}=1.970154\).
Step 5: half-width \(=1.970154\times73.374059=144.5582\).
Step 6: \(1509.126\pm144.558=(1364.567,\ 1653.684)\).
4500 is farther from \(\bar x\) than 4000. The half-width 144.558 is a little larger than 143.148.
Q3. (a) At which \(x_{new}\) is the PI narrowest? (b) Calculate its 95% half-width. (c) Why does this half-width not decrease to 0 as \(n\to\infty\)?
Answer
(a) Only \(\frac{(x_{new}-\bar x)^2}{S_{xx}}\) changes with \(x_{new}\). It is 0 at \(x_{new}=\bar x=3637.864407\), where the PI is narrowest.
(b) \(\hat\sigma\sqrt{1+\frac1{236}+0}=72.35066237\times\sqrt{1.004237288}=72.35066237\times1.002116404=72.503786\).
Half-width \(=1.970154\times72.503786=142.8436\).
\(\hat y_{new}=335.432315+0.2608207153\times3637.864407=1284.262712\). PI: \(1284.263\pm142.844=(1141.419,\ 1427.106)\).
(c) As \(n\to\infty\), \(\frac1n\to0\), and the third term is 0 at \(\bar x\). The "1" stays.
The "1" is \(\mathrm{Var}[\epsilon_{new}]=\sigma^2\). More data improve the fitted line but do not remove \(\epsilon_{new}\).
The half-width stays near \(t_{1-\alpha/2,\,n-2}\,\hat\sigma\) or larger.
Unit 05Prediction intervals over a range of \(x\) values
Brainhead data, \(n=236\). Values from brainhead.csv, as in units 01–04:
05.1Calculate the prediction interval at many values of \(x_{new}\) Slides p.38
What Slides p.37–38
Slides p.38 shows this as code. For each \(x_{new}\), the code does four things:
The grid goes from 2773 to 4747, step 1: \(4747-2773+1=1975\) values. The p.39 plot joins all L and all U.
Only the PI has the term 1 under the square root.
How Added
- Find the quantile \(t_{1-\alpha/2,\,n-2}\).
- Calculate \(\hat y_{new}=\hat\beta_0+\hat\beta_1x_{new}\).
- Calculate the distance term \(k=(x_{new}-\bar x)^2/S_{xx}\).
- Calculate the standard error \(\hat\sigma\sqrt{1+1/n+k}\).
- Multiply the quantile by the standard error to get the half-width.
- Subtract the half-width from \(\hat y_{new}\) to get L. Add it to get U.
For the band, do steps 2–6 at each grid value. The quantile does not change.
Self-check: ① \((L+U)/2=\hat y_{new}\). ② \(1+1/n+k\) is a little larger than 1. ③ At \(x_{new}=4000\), the PI is (1235.568, 1521.863), as in unit 04.
Example 1 · 95% PI at the smallest head size, \(x_{new}=2773\) Added
Quantile How step 1
Predicted value How step 2
Distance term How step 3
Standard error How step 4
\(1/n=1/236=0.004237\).
Half-width How step 5
Limits How step 6
95% PIs at four grid points (data file):
Self-check ①: \((914.119+1203.257)/2=1058.688=\hat y_{new}\). ▲
Why Added
Each How step gives one part of the p.37 formula: step 1 the quantile, step 2 \(\hat y_{new}\), steps 3–4 the standard error, steps 5–6 the limits.
Unit 04 (Slides p.35): \(\mathrm{Var}[\hat y_{new}-y_{new}]=\sigma^2\left(1+\frac1n+\frac{(x_{new}-\bar x)^2}{S_{xx}}\right)\). The 1 is \(\mathrm{Var}[y_{new}]=\sigma^2\). ∎
05.2Read the plot: the PI is much wider than the CI Slides p.39
What Slides p.39
The CI for \(\mu_0\) (Lecture 4 p.20) is \(\hat\mu_0\pm t_{1-\alpha/2,\,n-2}\,\hat\sigma\sqrt{\frac1n+\frac{(x_0-\bar x)^2}{\sum_{i=1}^n(x_i-\bar x)^2}}\), without the 1.
• Note the prediction intervals are much wider than the CIs before!
• Note also the lines are not parallel (slightly wider at the edges)
Note 1 compares PI and CI widths. Note 2: the PI is a little wider near the smallest and largest \(x\).
How Added
- Select \(\bar x\), \(\min x_i\), \(\max x_i\), and one more \(x\).
- Calculate the PI width U − L at each \(x\).
- Calculate the CI width at the same \(x\).
- Divide the PI width by the CI width.
- Compare the PI width at \(\bar x\) with the PI width at the edges.
A ratio much larger than 1 supports note 1. Edge widths a little larger than the center width support note 2.
Self-check: ① Both widths are smallest at \(\bar x\), where \((x-\bar x)^2/S_{xx}=0\). ② Both intervals have the midpoint \(\hat\beta_0+\hat\beta_1x\).
Example 2 · Widths in the brainhead data Added
PI widths from Section 05.1. CI widths use the same steps without the 1.
Note 1: the PI is 4.85 to 15.39 times as wide as the CI, most at \(\bar x\).
Note 2: the PI width is 285.687 at \(\bar x\), and 289.138 and 291.341 at the edges: only 3.451 and 5.654 g more.
The CI width grows from 18.557 to 60.056, more than 3 times.
Count (Added, data file): 226 of 236 points are in the 95% PI at their own \(x_i\): 95.8%, near 95%. Only 41 points are in the CI band. ▲
Why Added
Let \(k=\frac{(x-\bar x)^2}{S_{xx}}\ge0\).
At \(x=\bar x\), \(k=0\).
Agrees with 15.39 at \(\bar x\). ∎
Note 2: in the PI, the 1 is the largest term. At the right edge, \(k\) is only 0.040140. The square root grows only from \(\sqrt{1.004237}\) to \(\sqrt{1.044377}\). Without the 1, the same \(k\) has a large effect on the CI.
05.3Fitted values, the CI for the mean, and the PI together Slides p.40
What Slides p.40
Slides p.40 is code only, with no numbers. It gives three quantities from the fitted model:
At the same \(x\), \(\hat\mu_0=\hat y_{new}\). Only the standard error differs.
How Added
- Calculate the center \(\hat\beta_0+\hat\beta_1x\) for both intervals.
- Calculate \(k=(x-\bar x)^2/S_{xx}\).
- Calculate the CI standard error \(\hat\sigma\sqrt{1/n+k}\).
- Calculate the PI standard error \(\hat\sigma\sqrt{1+1/n+k}\).
- Multiply each by \(t_{1-\alpha/2,\,n-2}\) to get the two half-widths.
- Subtract each half-width from the center and add it.
Self-check: ① Same midpoint. ② The PI contains the CI.
Example 3 · Both intervals at \(x=3000\) Added
Center How step 1
Distance term How step 2
CI standard error How step 3
PI standard error How step 4
Half-widths How step 5
Limits How step 6
Midpoint 1117.894 for both. CI width 37.727, PI width 287.569. The PI contains the CI. ▲
A fitted value uses step 1 only. Person 1 has \(x_1=4512\): \(\hat y_1=335.432315+0.2608207\times4512=335.432315+1176.823068=1512.255\) g (Added).
Why Added
Both intervals use the fitted line at \(x\) as the center. The CI targets the fixed \(\mu_0\): only the error in \(\hat\beta_0,\hat\beta_1\) counts. The PI targets \(y_{new}=\beta_0+\beta_1x_{new}+\epsilon_{new}\): the variance \(\sigma^2\) of \(\epsilon_{new}\) also counts. ∎
05.4Practice Added
Use \(n=236\), \(\hat\beta_0=335.432315\), \(\hat\beta_1=0.2608207\), \(\hat\sigma=72.35066\), \(\bar x=3637.8644\), \(S_{xx}=30647233.66\).
Q1. A new person has head size 3500 cm³. Calculate a 90% PI for this person's brain weight by hand. Use \(t_{0.95,\,234}=1.651391\).
Answer
Q2. At \(x=\bar x\), show that the 95% PI width divided by the 95% CI width equals \(\sqrt{n+1}\). Evaluate it for the brainhead data.
Answer
At \(x=\bar x\), the distance term is 0.
Check: \(285.687/18.557=15.39\).
Q3. Two 95% intervals at \(x=3000\) are (1099.031, 1136.758) and (974.110, 1261.679). (a) Which is the CI for the mean response, and which is the PI? (b) Why do both have the same midpoint?
Answer
(a) The first (width 37.727) is the CI. The second (width 287.569) is the PI: its standard error has the extra 1 from \(\sigma^2\).
(b) Both have the center \(\hat\beta_0+\hat\beta_1x=335.432315+0.2608207\times3000=1117.894\). The mean estimate and the predicted value are the same number.
Unit 06Practice questions Q1 and Q2
Section page (p.41), Q1: MLEs and \(\hat\sigma/\hat\sigma_{MLE}\) (p.42), Q2: two CIs and one PI (p.43), similar exercises (Added).
Slides p.41 · Section page "Practice"
The two questions use no data set, only the numbers given.
06.1Practice Q1: MLEs and the ratio \(\hat\sigma/\hat\sigma_{MLE}\) Slides p.42
What · The question Slides p.42
(b) For \(n=20\), find the ratio \(\hat\sigma/\hat\sigma_{MLE}\).
(c) Suppose \(n=50\), and \(S_{xx}=180,\ \bar x=4.8,\ S_{xy}=353,\ \sum_{i=1}^n x_iy_i=3378\). Compute the MLEs for \(\beta_0\) and \(\beta_1\).
With normal errors, the least squares estimators are the MLEs.
\(\hat\sigma_{MLE}\) in Q1 is \(\hat\sigma_{ML}\). It divides by \(n\); \(\hat\sigma^2\) divides by \(n-2\). The numerator \(\sum e_i^2\) is the same.
How · The steps Added
- (a) Write the MLEs. ① Write \(\hat\beta_1=S_{xy}/S_{xx}\). ② Replace \(S_{xx}\) with \((n-1)s_x^2\). ③ Write \(\hat\beta_0=\bar y-\hat\beta_1\bar x\). ④ Put ② into ③.
- (b) Find the ratio. ① Write \(\hat\sigma^2\) and \(\hat\sigma^2_{MLE}\). ② Divide them; \(\sum e_i^2\) cancels. ③ Take the square root. ④ Put in \(n\).
- (c) Calculate the estimates. ① Calculate \(\hat\beta_1=S_{xy}/S_{xx}\). ② Find \(\bar y\) from \(\sum x_iy_i=S_{xy}+n\bar x\bar y\). ③ Calculate \(\hat\beta_0=\bar y-\hat\beta_1\bar x\).
Self-check: (a) contains only \(\bar x,\bar y,S_{xy},s_x^2\), \(n\), not \(S_{xx}\). (b) is more than 1, because \(n-2<n\). In (c), \(S_{xy}+n\bar x\bar y=3378\).
Example · The answers Added
Answer to Q1(a)
Write the slope L3 p.7 · \(\hat\beta_1=S_{xy}/S_{xx}\)
Basis: OLS = MLE with normal errors.
Replace \(S_{xx}\) L2 p.5 · \(s_x^2=S_{xx}/(n-1)\)
Write the intercept L3 p.7 · \(\hat\beta_0=\bar y-\hat\beta_1\bar x\)
Answer to Q1(b)
Write the two estimators L2 p.35 · \(\hat\sigma^2_{ML}\) and \(\hat\sigma^2\)
Divide and take the square root (Why (ii))
Put in \(n=20\)
\(\hat\sigma\) is approximately 5.4% larger than \(\hat\sigma_{MLE}\).
Answer to Q1(c)
Calculate the slope L3 p.7 · \(\hat\beta_1=S_{xy}/S_{xx}\)
Put the numbers in the identity \(\sum x_iy_i=S_{xy}+n\bar x\bar y\) (Why (iii))
Find \(\bar y\)
Calculate the intercept L3 p.7 · \(\hat\beta_0=\bar y-\hat\beta_1\bar x\)
Self-check: \(353+240\times12.604167\approx3378\).
\(\hat\beta_1\approx1.9611\), \(\hat\beta_0\approx3.1908\).
Why · The derivations Added
(i) \(S_{xx}\) and the sample variance
Basis: Lecture 2 · p.5
Basis: definition of \(S_{xx}\)
(ii) The ratio \(\hat\sigma/\hat\sigma_{MLE}\)
Basis: Lecture 2 · p.35
Basis: both are positive
(iii) The identity \(\sum x_iy_i=S_{xy}+n\bar x\bar y\)
Basis: \(\sum y_i=n\bar y\), \(\sum x_i=n\bar x\)
06.2Practice Q2: two confidence intervals and one prediction interval Slides p.43
What · The question Slides p.43
Also we know that if \(T\sim t_{(8)}\): \(P(T>-1.86)=0.95\), \(P(|T|>2.75)=0.025\), \(P(T<2.31)=0.975\).
(a) Calculate a two-sided 95% confidence interval for \(\beta_1\).
(b) Calculate a two-sided 95% confidence interval for \(\beta_0\).
(c) Calculate a 90% prediction interval for a new response at \(x_{new}=5\).
More generally a \(100\times(1-\alpha)\%\) CI is: \(\hat\beta_1\pm t_{1-\alpha/2,n-2}\times \mathrm{SE}(\hat\beta_1)\).
\(\hat\sigma\) for \(\sigma\) gives \(\mathrm{SE}(\hat\beta_0)=\hat\sigma\sqrt{\frac1n+\frac{\bar x^2}{S_{xx}}}\). The CI is \(\hat\beta_0\pm t_{1-\alpha/2,n-2}\,\mathrm{SE}(\hat\beta_0)\) (Lecture 3 · p.36).
How · The steps Added
- Step 0: Read the quantiles. ① Find \(1-\alpha/2\): 95% gives 0.975, 90% gives 0.95. ② Find \(P(T<c)=1-\alpha/2\) in the question. ③ Change \(P(T>-c)\) to \(P(T<c)\) by symmetry.
- (a) CI for \(\beta_1\). ① Calculate \(\mathrm{SE}(\hat\beta_1)=\hat\sigma/\sqrt{S_{xx}}\). ② Multiply by \(t_{0.975,8}\). ③ Write \(\hat\beta_1\) plus or minus this number.
- (b) CI for \(\beta_0\). ① Calculate \(\frac1n+\frac{\bar x^2}{S_{xx}}\). ② Take the square root and multiply by \(\hat\sigma\): \(\mathrm{SE}(\hat\beta_0)\). ③ Write \(\hat\beta_0\pm t_{0.975,8}\,\mathrm{SE}(\hat\beta_0)\).
- (c) 90% PI. ① Calculate \(\hat y_{new}=\hat\beta_0+\hat\beta_1x_{new}\). ② Calculate \(1+\frac1n+\frac{(x_{new}-\bar x)^2}{S_{xx}}\). ③ Take the square root and multiply by \(\hat\sigma\). ④ Multiply by \(t_{0.95,8}\). Write \(\hat y_{new}\) plus or minus this number.
Self-check: Degrees of freedom \(n-2=8\). Each interval has the point estimate at its center. The PI has an extra "1" under the square root.
Example · The answers Added
Step 0: read \(t_{0.975,8}\) and \(t_{0.95,8}\) from the question
A 95% interval needs \(t_{0.975,8}\) How Step 0 ①
Third statement definition of a quantile
A 90% interval needs \(t_{0.95,8}\) How Step 0 ①
First statement, by symmetry (Why (i)) How Step 0 ③
\(P(|T|>2.75)=0.025\) puts 0.0125 in each tail: a two-sided 97.5% interval. Q2 does not use it.
Answer to Q2(a): 95% CI for \(\beta_1\)
Standard error L4 p.5 · \(\mathrm{SE}(\hat\beta_1)=\hat\sigma/\sqrt{S_{xx}}\)
Half-width Step 0 · \(t_{0.975,8}=2.31\)
Interval L4 p.5 · \(\hat\beta_1\pm t_{0.975,n-2}\mathrm{SE}(\hat\beta_1)\)
Answer to Q2(b): 95% CI for \(\beta_0\)
SE formula L3 p.24 · \(\mathrm{SE}(\hat\beta_0)\)
Put in \(n=10,\ \bar x=0,\ S_{xx}=16\)
Square root, times \(\hat\sigma\)
Half-width Step 0 · \(t_{0.975,8}=2.31\)
Interval L3 p.36 · \(\hat\beta_0\pm t\cdot \mathrm{SE}(\hat\beta_0)\)
Answer to Q2(c): 90% PI at \(x_{new}=5\)
Center L4 p.37 · \(\hat y_{new}=\hat\beta_0+\hat\beta_1x_{new}\)
Terms under the square root L4 p.37 · \(1+\frac1n+\frac{(x_{new}-\bar x)^2}{S_{xx}}\)
Square root, times \(\hat\sigma\)
Half-width Step 0 · \(t_{0.95,8}=1.86\)
Interval L4 p.37 · \(\hat y_{new}\pm t_{1-\alpha/2,n-2}\,\hat\sigma\sqrt{\cdots}\)
Why · The derivations Added
Only the two new steps of Q2.
(i) From \(P(T>-1.86)=0.95\) to \(t_{0.95,8}=1.86\)
Basis: the question
Basis: \(-T\) has the same distribution as \(T\) (symmetry)
Basis: \(P(T<t_{q,8})=q\)
(ii) A 90% interval uses \(t_{0.95,8}\)
Basis: Slides p.37, \(n-2=8\)
06.3Practice Added
Model \(y_i=\beta_0+\beta_1x_i+\epsilon_i\), \(\epsilon_i\overset{iid}{\sim}N(0,\sigma^2)\). \(n=12\), \(S_{xx}=40\), \(\bar x=3\), \(S_{xy}=60\), \(\bar y=10\). Calculate the MLEs for \(\beta_0\) and \(\beta_1\).
Answer
Slope L3 p.7 · \(\hat\beta_1=S_{xy}/S_{xx}\)
Intercept L3 p.7 · \(\hat\beta_0=\bar y-\hat\beta_1\bar x\)
Setting of Practice Q2 (\(n=10,\ \hat\beta_0=-2,\ \hat\beta_1=5,\ \hat\sigma=0.4\)). Find \(\hat\sigma_{MLE}\).
Answer
Ratio formula 06.1 Why (ii) · \(\hat\sigma/\hat\sigma_{MLE}=\sqrt{n/(n-2)}\)
Put in \(n=10\), \(\hat\sigma=0.4\)
Setting of Practice Q2 (\(n=10,\ \hat\beta_1=5,\ \hat\beta_0=-2,\ S_{xx}=16,\ \bar x=0,\ \hat\sigma=0.4\), \(P(T<2.31)=0.975\) for \(T\sim t_{(8)}\)). Calculate a 95% PI for a new response at \(x_{new}=2\).
Answer
Quantile How Step 0
Center L4 p.37 · \(\hat y_{new}\)
Terms under the square root L4 p.37
Times \(\hat\sigma\), then times the quantile
Interval