| term | estimate | std.error | statistic | p.value |
|---|---|---|---|---|
| (Intercept) | 126.684 | 4.665 | 27.156 | 0 |
| bill_length_mm | 1.690 | 0.105 | 16.034 | 0 |
2026-11-19
– Homework-3 assigned 11-13; due 11-20
– Rubric assignment is out now; due 11-27
– Don’t forget about the Statistics Experience (12-1)
– Exam-2 grades are LIVE
> regrade window until Friday at 5pm
– Final Exam
> December 3rd 3:30pm in our classroom
> Cumulative with a focus on unit-III
– Optional Homework-4 coming
> "Graded" for completeness
> + 3 EC on the Final
> Help you study for regression
> key will be posted
– Next Tuesday
> finish all things regression
> review
– Tuesday after break
> review for final
We are going to take 5-minutes to fill out the course evaluation: http://go.ncsu.edu/cesurvey
These are important!
I take them very seriously, and will read them after the semester The department takes them very seriously
You are my favorite ST 312 class I’ve ever taught at NC State!
– What are they?
– Why do we make them?
We can calculate three types of confidence intervals:
– Confidence interval for \(\beta_1\)
– Confidence interval for the mean response
– Prediction interval for a brand new observation
\(\hat{\beta}_1 \pm t^*_{n-2} \cdot SE(\hat{\beta}_1)\)
\(\hat{\mu}_y \pm t^*_{n-2} \cdot SE(\hat{\mu}_y)\)
\(\hat{y} \pm t^*_{n-2} \cdot SE(\hat{y})\)
\(\hat{\beta}_1 \pm t^*_{n-2} \cdot SE(\hat{\beta}_1)\)
| term | estimate | std.error | statistic | p.value |
|---|---|---|---|---|
| (Intercept) | 126.684 | 4.665 | 27.156 | 0 |
| bill_length_mm | 1.690 | 0.105 | 16.034 | 0 |
\(1.690 \pm 1.96(0.105) = (1.4842,\ 1.8958)\)
We are 95% confident that, if we increase bill length by 1 mm, we estimate the true/population mean flipper length to increase between 1.48 and 1.90mm.
| term | estimate | std.error | statistic | p.value |
|---|---|---|---|---|
| (Intercept) | 126.684 | 4.665 | 27.156 | 0 |
| bill_length_mm | 1.690 | 0.105 | 16.034 | 0 |
What is the estimated mean bill flipper length for when a penguin has a bill length of 40 mm?
What would you predict a new penguin’s flipper length be if they had a bill length of 40 mm?
\(X_\text{given}\) = What we set x equal to
\[\text{SE}_{\hat{\mu}_{Y}|X_g} = \sqrt{\hat{\sigma}^2 \left[\frac{1}{n} + \frac{(X_\text{given} - \bar{X})^2}{\sum_{i=1}^{n} (X_i - \bar{X})^2}\right]}\]
\[\text{SE}_{\text{Prediction}} = \sqrt{\hat{\sigma}^2 + \hat{\sigma}^2 \left[ \frac{1}{n} + \frac{(X_\text{given} - \bar{X})^2}{\sum_{i=1}^{n} (X_i - \bar{X})^2} \right]}\] What’s the difference?
\[\text{SE}_{\hat{\mu}_{Y}|X_g} = \sqrt{\hat{\sigma}^2 \left[\frac{1}{n} + \frac{(X_\text{given} - \bar{X})^2}{\sum_{i=1}^{n} (X_i - \bar{X})^2}\right]}\]
This accounts for the uncertainty of our fitted line
\[\text{SE}_{\text{Prediction}} = \sqrt{\hat{\sigma}^2 + \hat{\sigma}^2 \left[ \frac{1}{n} + \frac{(X_\text{given} - \bar{X})^2}{\sum_{i=1}^{n} (X_i - \bar{X})^2} \right]}\]
This accounts for the uncertainty of our fitted line AND variability of individual data points around the true population regression line
95% confidence interval
fit lwr upr
1 194.2869 192.8945 195.6793
95% prediction interval
fit lwr upr
1 194.2869 173.3384 215.2354
You will not be asked to calculate confidence intervals for mean response/prediction, but you may be asked:
– to interpret these
– know the relationship between
Multiple linear regression is used to model the relationship between a single dependent/response variable and two or more independent/explanatory variables.
Maybe the relationship is more complex than just Y vs X…. and you want your model to pick up on that!
By including a relevant variable (\(X_2\)), you move its effect out of the error term and into the model, and now have a better understanding about what’s going on.
We can use hypothesis testing to find the most appropriate model
– Simple Linear Regression
– Multiple Linear Regression (additive)
– Multiple Linear Regression (interaction)
\[\mathbf{\hat{Y} = \hat{\beta}_0 + \hat{\beta}_1 X_1}\]
\[ \hat{Y} = \hat{\beta}_0 + \hat{\beta}_1 X_1 + \hat{\beta}_2 X_2 + \dots + \hat{\beta}_k X_k \]
Simple Linear Regression
| term | estimate |
|---|---|
| (Intercept) | 126.684 |
| bill_length_mm | 1.690 |
Multiple Linear Regression
| term | estimate |
|---|---|
| (Intercept) | 147.951 |
| bill_length_mm | 1.083 |
| speciesChinstrap | -5.004 |
| speciesGentoo | 17.799 |
Takeaway: Coefficients are dependent on other variables in the model!
Some of the relationship between bill length and flipper length was attributed to species!
Multiple Linear Regression
| term | estimate |
|---|---|
| (Intercept) | 147.951 |
| bill_length_mm | 1.083 |
| speciesChinstrap | -5.004 |
| speciesGentoo | 17.799 |
Is this model better than simple linear regression? That is, should we include species? Is species important?
The idea is to…
…see if the reduction in unexplained variance (the reduction in Residual Sum of Squares, RSS) when moving from \(Model_\text{reduced}\) to \(Model_\text{Full}\) is statistically significant.
or, is species a good predictor/worth it to include!
This sounds like something we’ve done before……
\(\mathbf{F} = \frac{\frac{\text{SS}_{\text{Between}}}{k - 1}}{\frac{\text{SS}_{\text{Within}}}{N - k}}\)
Now let’s do this with regression…
\(H_o\): \(\beta_2 = \beta_3 = 0\)
\(H_a\): At least one of the betas differ from zero
\[F = \frac{(\text{RSS}_R - \text{RSS}_F) / (\text{df}_R - \text{df}_F)}{\text{MSE}_F}\]
Check for both models!
– Independence
– Linearity
– Normality of residuals
– Equal Variance
… and they need to be nested models
How do we check it?
What does it mean to be nested?
We can perform transformations to help fix equal variance / normality. Your book talks about them.
You need to check assumptions for both models
Analysis of Variance Table
Model 1: flipper_length_mm ~ bill_length_mm
Model 2: flipper_length_mm ~ bill_length_mm + species
Res.Df RSS Df Sum of Sq F Pr(>F)
1 340 38394
2 338 11471 2 26923 396.64 < 2.2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
What can we conclude?
\(df_1 = p_{\text{full}} - p_{\text{reduced}} = 4 - 2 = 2\); this includes all indicator variables in the model (4 = intercept + bill length + chinstrap + gentoo)
\(df_2 = n - p_{\text{full}} = 342 - 4 = 338\)
\(F \sim F_{2,338}\)
Is it worth it?
First, let’s write out the estimated model.
# A tibble: 6 × 5
term estimate std.error statistic p.value
<chr> <dbl> <dbl> <dbl> <dbl>
1 (Intercept) 159. 6.90 23.0 4.72e-71
2 speciesChinstrap -12.3 12.5 -0.986 3.25e- 1
3 speciesGentoo -7.83 10.6 -0.736 4.63e- 1
4 bill_length_mm 0.800 0.178 4.50 9.17e- 6
5 speciesChinstrap:bill_length_mm 0.207 0.276 0.750 4.54e- 1
6 speciesGentoo:bill_length_mm 0.591 0.246 2.40 1.67e- 2
\[F = \frac{(\text{RSS}_R - \text{RSS}_F) / (\text{df}_R - \text{df}_F)}{\text{MSE}_F}\]
Analysis of Variance Table
Model 1: flipper_length_mm ~ bill_length_mm + species
Model 2: flipper_length_mm ~ bill_length_mm * species
Res.Df RSS Df Sum of Sq F Pr(>F)
1 338 11471
2 336 11272 2 199.66 2.9759 0.05235 .
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
\(df_1 = p_{\text{interaction}} - p_{\text{additive}} = 6 - 4 = 2\)
\(df_2 = n - p_{\text{interaction}} = 342 - 6 = 336\)
\(F \sim F_{2,336}\)
Call:
lm(formula = flipper_length_mm ~ bill_length_mm + bill_depth_mm,
data = plot_data)
Residuals:
Min 1Q Median 3Q Max
-37.731 -5.855 0.041 6.112 23.059
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 194.31175 6.33800 30.66 <2e-16 ***
bill_length_mm 1.41476 0.08802 16.07 <2e-16 ***
bill_depth_mm -3.23801 0.24335 -13.31 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 8.626 on 339 degrees of freedom
Multiple R-squared: 0.6259, Adjusted R-squared: 0.6237
F-statistic: 283.6 on 2 and 339 DF, p-value: < 2.2e-16
# A tibble: 4 × 5
term estimate std.error statistic p.value
<chr> <dbl> <dbl> <dbl> <dbl>
1 (Intercept) -120. 42.4 -2.84 4.85e- 3
2 bill_length_mm 8.37 0.932 8.98 1.94e-17
3 bill_depth_mm 14.5 2.37 6.09 3.03e- 9
4 bill_length_mm:bill_depth_mm -0.392 0.0524 -7.49 6.05e-13