-
-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy path05-linear-regression.Rmd
More file actions
1848 lines (1284 loc) · 88 KB
/
05-linear-regression.Rmd
File metadata and controls
1848 lines (1284 loc) · 88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Linear Regression {#linear-regression}
This chapter develops the classical linear model as the cornerstone of regression methodology. It presents [Ordinary Least Squares](#ordinary-least-squares), its geometric and probabilistic interpretations, and the Gauss-Markov theorem. Diagnostics for multicollinearity, heteroskedasticity, and influential observations are paired with remedies such as Generalized Least Squares and robust variance estimation. Extensions to maximum-likelihood estimation unify treatment of continuous and discrete outcomes, while penalized approaches---including ridge, lasso, and elastic-net---address high-dimensional feature spaces. Finally, we introduce Partial Least Squares for dimension reduction and demonstrate applications in marketing analytics, experimental psychology, and economic forecasting.
Figure \@ref(fig:fig-inference-framework) sketches the overall pipeline from population observations through identification assumptions to sample-based estimators.
```{r fig-inference-framework, fig.cap="Framework for Statistical Inference and Causal Interpretation", fig.alt="A flowchart illustrating the framework for statistical estimation. It begins with the population distribution of observations, which flows into two paths: one toward population parameters via identification assumptions, and the other toward sample-based estimators. The framework highlights consistency, assumptions, and causal interpretation.", out.width="90%", fig.align="center", echo=FALSE}
knitr::include_graphics("images/econometrics.PNG")
```
<!-- ::: {style="text-align:center"} -->
<!-- {width="450" height="200"} -->
<!-- ::: -->
Linear regression is one of the most fundamental tools in statistics and econometrics, widely used for modeling relationships between variables. It forms the cornerstone of predictive analysis, enabling us to understand and quantify how changes in one or more explanatory variables are associated with a dependent variable. Its simplicity and versatility make it an essential tool in fields ranging from economics and marketing to healthcare and environmental studies.
At its core, linear regression addresses questions about associations rather than causation. For example:
- How are advertising expenditures associated with sales performance?
- What is the relationship between a company's revenue and its stock price?
- How does the level of education correlate with income?
These questions are about patterns in data---not necessarily causal effects. While regression can provide insights into potential causal relationships, establishing causality requires more than just regression analysis. It requires careful consideration of the study design, assumptions, and potential confounding factors.
So, why is it called "linear"? The term refers to the structure of the model, where the dependent variable (outcome) is modeled as a linear combination of one or more independent variables (predictors). For example, in simple linear regression, the relationship is represented as:
$$Y = \beta_0 + \beta_1 X + \epsilon,$$
where $Y$ is the dependent variable, $X$ is the independent variable, $\beta_0$ and $\beta_1$ are parameters to be estimated, and $\epsilon$ is the error term capturing randomness or unobserved factors.
Linear regression serves as a foundation for much of applied data analysis because of its wide-ranging applications:
1. **Understanding Patterns in Data:** Regression provides a framework to summarize and explore relationships between variables. It allows us to identify patterns such as trends or associations, which can guide further analysis or decision-making.
2. **Prediction:** Beyond exploring relationships, regression is widely used for making predictions. For instance, given historical data, we can use a regression model to predict future outcomes like sales, prices, or demand.
3. **Building Blocks for Advanced Techniques:** Linear regression is foundational for many advanced statistical and machine learning models, such as logistic regression, ridge regression, and neural networks. Mastering linear regression equips you with the skills to tackle more complex methods.
**Regression and Causality: A Crucial Distinction**
It's essential to remember that regression alone does not establish causation. For instance, a regression model might show a strong association between advertising and sales, but this does not prove that advertising directly causes sales to increase. Other factors---such as seasonality, market trends, or unobserved variables---could also influence the results.
Establishing causality requires additional steps, such as controlled experiments, instrumental variable techniques, or careful observational study designs. As we work through the details of linear regression, we'll revisit this distinction and highlight scenarios where causality might or might not be inferred.
------------------------------------------------------------------------
**What is an Estimator?**
At the heart of regression lies the process of **estimation**---the act of using data to determine the unknown characteristics of a population or model.
An **estimator** is a mathematical rule or formula used to calculate an estimate of an unknown quantity based on observed data. For example, when we calculate the average height of a sample to estimate the average height of a population, the sample mean is the estimator.
In the context of regression, the quantities we typically estimate are:
- **Parameters**: Fixed, unknown values that describe the relationship between variables (e.g., coefficients in a regression equation).
- **Estimating parameters** → Parametric models (finite parameters, e.g., coefficients in regression).
- **Functions**: Unknown relationships or patterns in the data, often modeled without assuming a fixed functional form.
- **Estimating functions** → Non-parametric models (focus on shapes or trends, not a fixed number of parameters).
------------------------------------------------------------------------
**Types of Estimators**
To better understand the estimation process, let's introduce two broad categories of estimators that we'll work with:
1. **Parametric Estimators**\
Parametric estimation focuses on a finite set of parameters that define a model. For example, in a simple linear regression:\
$$Y = \beta_0 + \beta_1 X + \epsilon,$$\
the task is to estimate the parameters $\beta_0$ (intercept) and $\beta_1$ (slope). Parametric estimators rely on specific assumptions about the form of the model (e.g., linearity) and the distribution of the error term (e.g., normality).
2. **Non-Parametric Estimators**\
Non-parametric estimation avoids assuming a specific functional form for the relationship between variables. Instead, it focuses on estimating patterns or trends directly from the data. For example, using a scatterplot smoothing technique to visualize how sales vary with advertising spend without imposing a linear or quadratic relationship.
These two categories reflect a fundamental trade-off in statistical analysis: **parametric models** are often simpler and more interpretable but require strong assumptions, while **non-parametric models** are more flexible but may require more data and computational resources.
------------------------------------------------------------------------
**Desirable Properties of Estimators**
Regardless of whether we are estimating parameters or functions, we want our estimators to possess certain desirable properties. Think of these as the "golden standards" that help us judge whether an estimator is reliable:
1. **Unbiasedness**\
An estimator is unbiased if it hits the true value of the parameter, on average, over repeated samples. Mathematically:\
$$E[\hat{\beta}] = \beta.$$\
This means that, across multiple samples, the estimator does not systematically overestimate or underestimate the true parameter.
2. **Consistency**\
Consistency ensures that as the sample size increases, the estimator converges to the true value of the parameter. Formally:\
$$plim\ \hat{\beta_n} = \beta.$$\
This property relies on the [Law of Large Numbers], which guarantees that larger samples reduce random fluctuations, leading to more precise estimates.
3. **Efficiency**\
Among all unbiased estimators, an efficient estimator has the smallest variance.
- The [Ordinary Least Squares](#ordinary-least-squares) method is efficient because it is the **Best Linear Unbiased Estimator (BLUE)** under the Gauss-Markov Theorem.
- For estimators that meet specific distributional assumptions (e.g., normality), maximum-likelihood estimators are asymptotically efficient, meaning they achieve the lowest possible variance as the sample size grows.
------------------------------------------------------------------------
**Why These Properties Matter**
Understanding these properties is crucial because they ensure that the methods we use for estimation are reliable, precise, and robust. Whether we are estimating coefficients in a regression model or uncovering a complex pattern in the data, these properties provide the foundation for statistical inference and decision-making.
Now that we've established what estimators are, the types we'll encounter, and their desirable properties, we can move on to understanding how these concepts apply specifically to the [Ordinary Least Squares](#ordinary-least-squares) method---the backbone of linear regression.
| **Estimation Method** | **Key Assumptions** | **Strengths** | **Limitations** |
|---|---|---|---|
| [Ordinary Least Squares](#ordinary-least-squares) | Errors have mean zero, constant variance, and are uncorrelated (the Gauss-Markov conditions); linearity in parameters and no perfect collinearity in $X$. Independence and normality are stronger assumptions used for inference, not for unbiasedness. | Simple, well-understood method; minimizes residual sum of squares with easily interpretable coefficients. | Sensitive to outliers and violations of normality; performs poorly under high multicollinearity. |
| Generalized Least Squares | Errors have a known correlation or heteroscedasticity structure that can be modeled. | Handles correlated or non-constant-variance errors; more flexible than OLS when the noise structure is known. | Requires specifying (or estimating) the error covariance structure; misspecification can introduce bias. |
| Maximum Likelihood | The underlying probability distribution (e.g., normal) must be specified correctly. | Provides a general framework for estimating parameters under well-defined probability models; extends to complex likelihoods. | Highly sensitive to model misspecification; may require more computation than OLS or GLS. |
| Penalized (Regularized) Estimators | Coefficients are assumed to be shrinkable; the model permits coefficient penalization. | Controls overfitting via regularization; handles high-dimensional data and many predictors; can perform feature selection (e.g., Lasso). | Requires choosing tuning parameter(s) (e.g., $\lambda$); interpretation of coefficients becomes less straightforward. |
| Robust Estimators | Less sensitive to heavy-tailed or outlier-prone distributions (weaker assumptions on the error structure). | Resistant to large deviations or outliers in data; often maintains good performance under mild model misspecification. | Less efficient if errors are truly normal; choice of robust method and tuning can be subjective. |
| Partial Least Squares | Predictors may be highly correlated and dimension reduction is desired. | Simultaneously reduces dimensionality and fits regression; works well with collinear, high-dimensional data. | Can be harder to interpret than OLS (latent components instead of original predictors); requires choosing the number of components. |
: Comparison of Estimation Methods in Regression Analysis
------------------------------------------------------------------------
## Ordinary Least Squares {#ordinary-least-squares}
Ordinary Least Squares (OLS) is the backbone of statistical modeling, a method so foundational that it often serves as the starting point for understanding data relationships. Whether predicting sales, estimating economic trends, or uncovering patterns in scientific research, OLS remains a critical tool. Its appeal lies in simplicity: OLS models the relationship between a dependent variable and one or more predictors by minimizing the squared differences between observed and predicted values.
------------------------------------------------------------------------
**Why OLS Works: Linear and Nonlinear Relationships**
[OLS](#ordinary-least-squares) rests on the Conditional Expectation Function (CEF), $E[Y | X]$, which describes the expected value of $Y$ given $X$. Regression shines in two key scenarios:
1. **Perfect Fit (Linear CEF):**\
If $E[Y_i | X_{1i}, \dots, X_{Ki}] = a + \sum_{k=1}^K b_k X_{ki}$, the regression of $Y_i$ on $X_{1i}, \dots, X_{Ki}$ exactly equals the CEF. In other words, the regression gives the true average relationship between $Y$ and $X$.\
If the true relationship is linear, regression delivers the exact CEF. For instance, imagine you're estimating the relationship between advertising spend and sales revenue. If the true impact is linear, [OLS](#ordinary-least-squares) will perfectly capture it.
2. **Approximation (Nonlinear CEF):**\
If $E[Y_i | X_{1i}, \dots, X_{Ki}]$ is nonlinear, [OLS](#ordinary-least-squares) provides the best linear approximation to this relationship. Specifically, it minimizes the expected squared deviation between the linear regression line and the nonlinear CEF.\
For example, the effect of advertising diminishes at higher spending levels? [OLS](#ordinary-least-squares) still works, providing the best linear approximation to this nonlinear relationship by minimizing the squared deviations between predictions and the true (but unknown) CEF.
In other words, regression is not just a tool for "linear" relationships---it's a workhorse that adapts remarkably well to messy, real-world data.
<!-- {width="80%"} -->
------------------------------------------------------------------------
### Simple Regression (Basic) Model
The simplest form of regression is a straight line:
$$
Y_i = \beta_0 + \beta_1 X_i + \epsilon_i
$$
where
- $Y_i$: The dependent variable or outcome we're trying to predict (e.g., sales, temperature).
- $X_i$: The independent variable or predictor (e.g., advertising spend, time).
- $\beta_0$: The intercept---where the line crosses the $Y$-axis when $X = 0$.
- $\beta_1$: The slope, representing the change in $Y$ for a one-unit increase in $X$.
- $\epsilon_i$: The error term, accounting for random factors that $X$ cannot explain.
Assumptions About the Error Term ($\epsilon_i$):
$$
\begin{aligned}
E(\epsilon_i) &= 0 \\
\text{Var}(\epsilon_i) &= \sigma^2 \\
\text{Cov}(\epsilon_i, \epsilon_j) &= 0 \quad \text{for all } i \neq j
\end{aligned}
$$
Since $\epsilon_i$ is random, $Y_i$ is also random:
$$
\begin{aligned}
E(Y_i) &= E(\beta_0 + \beta_1 X_i + \epsilon_i) \\
&= \beta_0 + \beta_1 X_i
\end{aligned}
$$
$$
\begin{aligned}
\text{Var}(Y_i) &= \text{Var}(\beta_0 + \beta_1 X_i + \epsilon_i) \\
&= \text{Var}(\epsilon_i) \\
&= \sigma^2
\end{aligned}
$$
Since $\text{Cov}(\epsilon_i, \epsilon_j) = 0$, the outcomes across observations are independent. Hence, $Y_i$ and $Y_j$ are uncorrelated as well, conditioned on the $X$'s.
------------------------------------------------------------------------
#### Estimation in Ordinary Least Squares
The goal of [OLS](#ordinary-least-squares) is to estimate the regression parameters ($\beta_0$, $\beta_1$) that best describe the relationship between the dependent variable $Y$ and the independent variable $X$. To achieve this, we minimize the sum of squared deviations between observed values of $Y_i$ and their expected values predicted by the model.
The deviation of an observed value $Y_i$ from its expected value, based on the regression model, is:
$$
Y_i - E(Y_i) = Y_i - (\beta_0 + \beta_1 X_i).
$$
This deviation represents the error in prediction for the $i$-th observation.
To ensure that the errors don't cancel each other out and to prioritize larger deviations, we consider the squared deviations. The sum of squared deviations, denoted by $Q$, is defined as:
$$
Q = \sum_{i=1}^{n} (Y_i - \beta_0 - \beta_1 X_i)^2.
$$
The goal of [OLS](#ordinary-least-squares) is to find the values of $\beta_0$ and $\beta_1$ that minimize $Q$. These values are called the **OLS estimators**.
To minimize $Q$, we take partial derivatives with respect to $\beta_0$ and $\beta_1$, set them to zero, and solve the resulting system of equations. After simplifying, the estimators for the slope ($b_1$) and intercept ($b_0$) are obtained as follows:
Slope ($b_1$):
$$
b_1 = \frac{\sum_{i=1}^{n} (X_i - \bar{X})(Y_i - \bar{Y})}{\sum_{i=1}^{n} (X_i - \bar{X})^2}.
$$
Here, $\bar{X}$ and $\bar{Y}$ represent the means of $X$ and $Y$, respectively. This formula reveals that the slope is proportional to the covariance between $X$ and $Y$, scaled by the variance of $X$.
Intercept ($b_0$):
$$
b_0 = \frac{1}{n} \left( \sum_{i=1}^{n} Y_i - b_1 \sum_{i=1}^{n} X_i \right) = \bar{Y} - b_1 \bar{X}.
$$
The intercept is determined by aligning the regression line with the center of the data.
------------------------------------------------------------------------
**Intuition Behind the Estimators**
- $b_1$ (Slope): This measures the average change in $Y$ for a one-unit increase in $X$. The formula uses deviations from the mean to ensure that the relationship captures the joint variability of $X$ and $Y$.
- $b_0$ (Intercept): This ensures that the regression line passes through the mean of the data points $(\bar{X}, \bar{Y})$, anchoring the model in the center of the observed data.
------------------------------------------------------------------------
Equivalently, we can also write these parameters in terms of covariances.
The covariance between two variables is defined as:
$$ \text{Cov}(X_i, Y_i) = E[(X_i - E[X_i])(Y_i - E[Y_i])] $$
Properties of Covariance:
1. $\text{Cov}(X_i, X_i) = \sigma^2_X$
2. If $E(X_i) = 0$ or $E(Y_i) = 0$, then $\text{Cov}(X_i, Y_i) = E[X_i Y_i]$
3. For $W_i = a + b X_i$ and $Z_i = c + d Y_i$,\
$\text{Cov}(W_i, Z_i) = bd \cdot \text{Cov}(X_i, Y_i)$
For a bivariate regression, the slope $\beta$ in a bivariate regression is given by:
$$ \beta = \frac{\text{Cov}(Y_i, X_i)}{\text{Var}(X_i)} $$
For a multivariate case, the slope for $X_k$ is:
$$ \beta_k = \frac{\text{Cov}(Y_i, \tilde{X}_{ki})}{\text{Var}(\tilde{X}_{ki})} $$
Where $\tilde{X}_{ki}$ represents the residual from a regression of $X_{ki}$ on the $K-1$ other covariates in the model.
The intercept is:
$$ \beta_0 = E[Y_i] - \beta_1 E(X_i) $$
Note:
- [OLS](#ordinary-least-squares) does not require the assumption of a specific distribution for the variables. Its robustness is based on the minimization of squared errors (i.e., no distributional assumptions).
#### Properties of Least Squares Estimators
The properties of the Ordinary Least Squares estimators ($b_0$ and $b_1$) are derived based on their statistical behavior. These properties provide insights into the accuracy, variability, and reliability of the estimates.
------------------------------------------------------------------------
##### Expectation of the OLS Estimators
The [OLS](#ordinary-least-squares) estimators $b_0$ (intercept) and $b_1$ (slope) are unbiased. This means their expected values equal the true population parameters:
$$
\begin{aligned}
E(b_1) &= \beta_1, \\
E(b_0) &= E(\bar{Y}) - \bar{X}\beta_1.
\end{aligned}
$$
Since the expected value of the sample mean of $Y$, $E(\bar{Y})$, is:
$$
E(\bar{Y}) = \beta_0 + \beta_1 \bar{X},
$$
the expected value of $b_0$ simplifies to:
$$
E(b_0) = \beta_0.
$$
Thus, $b_0$ and $b_1$ are unbiased estimators of their respective population parameters $\beta_0$ and $\beta_1$.
------------------------------------------------------------------------
##### Variance of the OLS Estimators
The variability of the [OLS](#ordinary-least-squares) estimators depends on the spread of the predictor variable $X$ and the error variance $\sigma^2$. The variances are given by:
Variance of $b_1$ (Slope):
$$
\text{Var}(b_1) = \frac{\sigma^2}{\sum_{i=1}^{n} (X_i - \bar{X})^2}.
$$
Variance of $b_0$ (Intercept):
$$
\text{Var}(b_0) = \sigma^2 \left( \frac{1}{n} + \frac{\bar{X}^2}{\sum_{i=1}^{n} (X_i - \bar{X})^2} \right).
$$
These formulas highlight that:
- $\text{Var}(b_1) \to 0$ as the number of observations increases, provided $X_i$ values are distributed around their mean $\bar{X}$.
- $\text{Var}(b_0) \to 0$ as $n$ increases, assuming $X_i$ values are appropriately selected (i.e., not all clustered near the mean).
------------------------------------------------------------------------
#### Mean Square Error (MSE)
The Mean Square Error (MSE) quantifies the average squared residual (error) in the model:
$$
MSE = \frac{SSE}{n-2} = \frac{\sum_{i=1}^{n} e_i^2}{n-2} = \frac{\sum_{i=1}^{n} (Y_i - \hat{Y}_i)^2}{n-2},
$$
where $SSE$ is the Sum of Squared Errors and $n-2$ represents the degrees of freedom for a simple linear regression model (two parameters estimated: $\beta_0$ and $\beta_1$).
The expected value of the MSE equals the error variance (i.e., unbiased Estimator of MSE:):
$$
E(MSE) = \sigma^2.
$$
------------------------------------------------------------------------
#### Estimating Variance of the OLS Coefficients
The sample-based estimates of the variances of $b_0$ and $b_1$ are expressed as follows:
Estimated Variance of $b_1$ (Slope):
$$
s^2(b_1) = \widehat{\text{Var}}(b_1) = \frac{MSE}{\sum_{i=1}^{n} (X_i - \bar{X})^2}.
$$
Estimated Variance of $b_0$ (Intercept):
$$
s^2(b_0) = \widehat{\text{Var}}(b_0) = MSE \left( \frac{1}{n} + \frac{\bar{X}^2}{\sum_{i=1}^{n} (X_i - \bar{X})^2} \right).
$$
These estimates rely on the MSE to approximate $\sigma^2$.
The variance estimates are unbiased:
$$
\begin{aligned}
E(s^2(b_1)) &= \text{Var}(b_1), \\
E(s^2(b_0)) &= \text{Var}(b_0).
\end{aligned}
$$
------------------------------------------------------------------------
**Implications of These Properties**
1. **Unbiasedness:** The unbiased nature of $b_0$ and $b_1$ ensures that, on average, the regression model accurately reflects the true relationship in the population.
2. **Decreasing Variance:** As the sample size $n$ increases or as the spread of $X_i$ values grows, the variances of $b_0$ and $b_1$ decrease, leading to more precise estimates.
3. **Error Estimation with MSE:** MSE provides a reliable estimate of the error variance $\sigma^2$, which feeds directly into assessing the reliability of $b_0$ and $b_1$.
#### Residuals in Ordinary Least Squares
Residuals are the differences between observed values ($Y_i$) and their predicted counterparts ($\hat{Y}_i$). They play a central role in assessing model fit and ensuring the assumptions of OLS are met.
The residual for the $i$-th observation is defined as:
$$
e_i = Y_i - \hat{Y}_i = Y_i - (b_0 + b_1 X_i),
$$
where:
- $e_i$: Residual for the $i$-th observation.
- $\hat{Y}_i$: Predicted value based on the regression model.
- $Y_i$: Actual observed value.
Residuals estimate the unobservable error terms $\epsilon_i$:
- $e_i$ is an estimate of $\epsilon_i = Y_i - E(Y_i)$.
- $\epsilon_i$ is always unknown because we do not know the true values of $\beta_0$ and $\beta_1$.
------------------------------------------------------------------------
##### Key Properties of Residuals
Residuals exhibit several mathematical properties that align with the OLS estimation process:
1. **Sum of Residuals**:\
The residuals sum to zero:
$$
\sum_{i=1}^{n} e_i = 0.
$$
This ensures that the regression line passes through the centroid of the data, $(\bar{X}, \bar{Y})$.
2. **Orthogonality of Residuals to Predictors**:\
The residuals are orthogonal (uncorrelated) to the predictor variable $X$:
$$
\sum_{i=1}^{n} X_i e_i = 0.
$$
This reflects the fact that the [OLS](#ordinary-least-squares) minimizes the squared deviations of residuals along the $Y$-axis, not the $X$-axis.
------------------------------------------------------------------------
##### Expected Values of Residuals
The expected values of residuals reinforce the unbiased nature of OLS:
1. **Mean of Residuals**:\
The residuals have an expected value of zero:
$$
E[e_i] = 0.
$$
2. **Orthogonality to Predictors and Fitted Values**:\
Residuals are uncorrelated with both the predictor variables and the fitted values:
$$
\begin{aligned}
E[X_i e_i] &= 0, \\
E[\hat{Y}_i e_i] &= 0.
\end{aligned}
$$
These properties highlight that residuals do not contain systematic information about the predictors or the fitted values, reinforcing the idea that the model has captured the underlying relationship effectively.
------------------------------------------------------------------------
##### Practical Importance of Residuals
1. **Model Diagnostics:**\
Residuals are analyzed to check the assumptions of OLS, including linearity, homoscedasticity (constant variance), and independence of errors. Patterns in residual plots can signal issues such as nonlinearity or heteroscedasticity.
2. **Goodness-of-Fit:**\
The sum of squared residuals, $\sum e_i^2$, measures the total unexplained variation in $Y$. A smaller sum indicates a better fit.
3. **Influence Analysis:**\
Large residuals may indicate outliers or influential points that disproportionately affect the regression line.
#### Inference in Ordinary Least Squares
Inference allows us to make probabilistic statements about the regression parameters ($\beta_0$, $\beta_1$) and predictions ($Y_h$). To perform valid inference, certain assumptions about the distribution of errors are necessary.
------------------------------------------------------------------------
Normality Assumption
- OLS estimation itself does **not** require the assumption of normality.
- However, to conduct hypothesis tests or construct confidence intervals for $\beta_0$, $\beta_1$, and predictions, distributional assumptions are necessary.
- Inference on $\beta_0$ and $\beta_1$ is **robust** to moderate departures from normality, especially in large samples due to the [Central Limit Theorem].
- Inference on predicted values, $Y_{pred}$, is more sensitive to normality violations.
------------------------------------------------------------------------
When we assume a **normal error model**, the response variable $Y_i$ is modeled as:
$$
Y_i \sim N(\beta_0 + \beta_1 X_i, \sigma^2),
$$
where:
- $\beta_0 + \beta_1 X_i$: Mean response
- $\sigma^2$: Variance of the errors
Under this model, the sampling distributions of the OLS estimators, $b_0$ and $b_1$, can be derived.
------------------------------------------------------------------------
##### Inference for $\beta_1$ (Slope)
Under the normal error model:
1. **Sampling Distribution of** $b_1$:
$$
b_1 \sim N\left(\beta_1, \frac{\sigma^2}{\sum_{i=1}^{n} (X_i - \bar{X})^2}\right).
$$
This indicates that $b_1$ is an unbiased estimator of $\beta_1$ with variance proportional to $\sigma^2$.
2. **Test Statistic:**
$$
t = \frac{b_1 - \beta_1}{s(b_1)} \sim t_{n-2},
$$
where $s(b_1)$ is the standard error of $b_1$: $$
s(b_1) = \sqrt{\frac{MSE}{\sum_{i=1}^{n} (X_i - \bar{X})^2}}.
$$
3. **Confidence Interval:**
A $(1-\alpha) 100\%$ confidence interval for $\beta_1$ is:
$$
b_1 \pm t_{1-\alpha/2; n-2} \cdot s(b_1).
$$
------------------------------------------------------------------------
##### Inference for $\beta_0$ (Intercept)
1. **Sampling Distribution of** $b_0$:
Under the normal error model, the sampling distribution of $b_0$ is:
$$
b_0 \sim N\left(\beta_0, \sigma^2 \left(\frac{1}{n} + \frac{\bar{X}^2}{\sum_{i=1}^{n} (X_i - \bar{X})^2}\right)\right).
$$
2. **Test Statistic:**
$$
t = \frac{b_0 - \beta_0}{s(b_0)} \sim t_{n-2},
$$
where $s(b_0)$ is the standard error of $b_0$: $$
s(b_0) = \sqrt{MSE \left(\frac{1}{n} + \frac{\bar{X}^2}{\sum_{i=1}^{n} (X_i - \bar{X})^2}\right)}.
$$
3. **Confidence Interval:**
A $(1-\alpha) 100\%$ confidence interval for $\beta_0$ is:
$$
b_0 \pm t_{1-\alpha/2; n-2} \cdot s(b_0).
$$
------------------------------------------------------------------------
##### Mean Response
In regression, we often estimate the mean response of the dependent variable $Y$ for a given level of the predictor variable $X$, denoted as $X_h$. This estimation provides a predicted average outcome for a specific value of $X$ based on the fitted regression model.
- Let $X_h$ represent the level of $X$ for which we want to estimate the mean response.
- The mean response when $X = X_h$ is denoted as $E(Y_h)$.
- A point estimator for $E(Y_h)$ is $\hat{Y}_h$, which is the predicted value from the regression model:
$$
\hat{Y}_h = b_0 + b_1 X_h.
$$
The estimator $\hat{Y}_h$ is unbiased because its expected value equals the true mean response $E(Y_h)$:
$$
\begin{aligned}
E(\hat{Y}_h) &= E(b_0 + b_1 X_h) \\
&= \beta_0 + \beta_1 X_h \\
&= E(Y_h).
\end{aligned}
$$
Thus, $\hat{Y}_h$ provides a reliable estimate of the mean response at $X_h$.
------------------------------------------------------------------------
The variance of $\hat{Y}_h$ reflects the uncertainty in the estimate of the mean response:
$$
\begin{aligned}
\text{Var}(\hat{Y}_h) &= \text{Var}(b_0 + b_1 X_h) \quad\text{(definition of }\hat{Y}_h\text{)}\\
&= \text{Var}\left((\bar{Y} - b_1 \bar{X}) + b_1 X_h\right)\quad\text{(since } b_0 = \bar{Y} - b_1 \bar{X}\text{)}\\
&= \text{Var}\left(\bar{Y} + b_1(X_h - \bar{X})\right)\quad\text{(factor out } b_1\text{)}\\
&= \text{Var}\left(\bar{Y} + b_1 (X_h - \bar{X}) \right) \\
&= \text{Var}(\bar{Y}) + (X_h - \bar{X})^2 \text{Var}(b_1) + 2(X_h - \bar{X}) \text{Cov}(\bar{Y}, b_1).
\end{aligned}
$$
Since $\text{Cov}(\bar{Y}, b_1) = 0$ (due to the independence of the errors, $\epsilon_i$), the variance simplifies to:
$$
\text{Var}(\hat{Y}_h) = \frac{\sigma^2}{n} + (X_h - \bar{X})^2 \frac{\sigma^2}{\sum_{i=1}^{n} (X_i - \bar{X})^2}.
$$
This can also be expressed as:
$$
\text{Var}(\hat{Y}_h) = \sigma^2 \left( \frac{1}{n} + \frac{(X_h - \bar{X})^2}{\sum_{i=1}^{n} (X_i - \bar{X})^2} \right).
$$
To estimate the variance of $\hat{Y}_h$, we replace $\sigma^2$ with $MSE$, the mean squared error from the regression:
$$
s^2(\hat{Y}_h) = MSE \left( \frac{1}{n} + \frac{(X_h - \bar{X})^2}{\sum_{i=1}^{n} (X_i - \bar{X})^2} \right).
$$
------------------------------------------------------------------------
Under the normal error model, the sampling distribution of $\hat{Y}_h$ is:
$$
\begin{aligned}
\hat{Y}_h &\sim N\left(E(Y_h), \text{Var}(\hat{Y}_h)\right), \\
\frac{\hat{Y}_h - E(Y_h)}{s(\hat{Y}_h)} &\sim t_{n-2}.
\end{aligned}
$$
This result follows because $\hat{Y}_h$ is a linear combination of normally distributed random variables, and its variance is estimated using $s^2(\hat{Y}_h)$.
------------------------------------------------------------------------
A $100(1-\alpha)\%$ confidence interval for the mean response $E(Y_h)$ is given by:
$$
\hat{Y}_h \pm t_{1-\alpha/2; n-2} \cdot s(\hat{Y}_h),
$$
where:
- $\hat{Y}_h$: Point estimate of the mean response,
- $s(\hat{Y}_h)$: Estimated standard error of the mean response,
- $t_{1-\alpha/2; n-2}$: Critical value from the $t$-distribution with $n-2$ degrees of freedom.
------------------------------------------------------------------------
##### Prediction of a New Observation
When analyzing regression results, it is important to distinguish between:
1. **Estimating the mean response** at a particular value of $X$.
2. **Predicting an individual outcome** for a particular value of $X$.
------------------------------------------------------------------------
Mean Response vs. Individual Outcome
- **Same Point Estimate**\
The formula for both the estimated mean response and the predicted individual outcome at $X = X_h$ is identical:\
$$
\hat{Y}_{pred} = \hat{Y}_h = b_0 + b_1 X_h.
$$
- **Different Variance**\
Although the point estimates are the same, the level of uncertainty differs. When predicting an individual outcome, we must consider not only the uncertainty in estimating the mean response ($\hat{Y}_h$) but also the additional random variation within the distribution of $Y$.
Therefore, **prediction intervals** (for individual outcomes) account for more uncertainty and are consequently wider than **confidence intervals** (for the mean response).
------------------------------------------------------------------------
To predict an individual outcome for a given $X_h$, we combine the mean response with the random error:
$$
Y_{pred} = \beta_0 + \beta_1 X_h + \epsilon.
$$
Using the least squares predictor:
$$
\hat{Y}_{pred} = b_0 + b_1 X_h,
$$
since $E(\epsilon) = 0$.
------------------------------------------------------------------------
The variance of the predicted value for a new observation, $Y_{pred}$, includes both:
1. Variance of the estimated mean response: $$
\sigma^2 \left( \frac{1}{n} + \frac{(X_h - \bar{X})^2}{\sum_{i=1}^{n} (X_i - \bar{X})^2} \right),
$$
2. Variance of the error term, $\epsilon$, which is $\sigma^2$.
Thus, the total variance is:
$$
\begin{aligned}
\text{Var}(Y_{pred}) &= \text{Var}(b_0 + b_1 X_h + \epsilon) \\
&= \text{Var}(b_0 + b_1 X_h) + \text{Var}(\epsilon) \\
&= \sigma^2 \left( \frac{1}{n} + \frac{(X_h - \bar{X})^2}{\sum_{i=1}^{n} (X_i - \bar{X})^2} \right) + \sigma^2 \\
&= \sigma^2 \left( 1 + \frac{1}{n} + \frac{(X_h - \bar{X})^2}{\sum_{i=1}^{n} (X_i - \bar{X})^2} \right).
\end{aligned}
$$
We estimate the variance of the prediction using $MSE$, the mean squared error:
$$
s^2(pred) = MSE \left( 1 + \frac{1}{n} + \frac{(X_h - \bar{X})^2}{\sum_{i=1}^{n} (X_i - \bar{X})^2} \right).
$$
Under the normal error model, the standardized predicted value follows a $t$-distribution with $n-2$ degrees of freedom:
$$
\frac{Y_{pred} - \hat{Y}_h}{s(pred)} \sim t_{n-2}.
$$
A $100(1-\alpha)\%$ prediction interval for $Y_{pred}$ is:
$$
\hat{Y}_{pred} \pm t_{1-\alpha/2; n-2} \cdot s(pred).
$$
------------------------------------------------------------------------
##### Confidence Band
In regression analysis, we often want to evaluate the uncertainty around the entire regression line, not just at a single value of the predictor variable $X$. This is achieved using a **confidence band**, which provides a confidence interval for the mean response, $E(Y) = \beta_0 + \beta_1 X$, over the entire range of $X$ values.
The Working-Hotelling confidence band is a method to construct simultaneous confidence intervals for the regression line. For a given $X_h$, the confidence band is expressed as:
$$
\hat{Y}_h \pm W s(\hat{Y}_h),
$$
where:
- $W^2 = 2F_{1-\alpha; 2, n-2}$,
- $F_{1-\alpha; 2, n-2}$ is the critical value from the $F$-distribution with 2 and $n-2$ degrees of freedom.
- $s(\hat{Y}_h)$ is the standard error of the estimated mean response at $X_h$:
$$
s^2(\hat{Y}_h) = MSE \left( \frac{1}{n} + \frac{(X_h - \bar{X})^2}{\sum_{i=1}^{n} (X_i - \bar{X})^2} \right).
$$
------------------------------------------------------------------------
**Key Properties of the Confidence Band**
1. **Width of the Interval:**
- The width of the confidence band changes with $X_h$ because $s(\hat{Y}_h)$ depends on how far $X_h$ is from the mean of $X$ ($\bar{X}$).
- The interval is narrowest at $X = \bar{X}$, where the variance of the estimated mean response is minimized.
2. **Shape of the Band:**
- The boundaries of the confidence band form a hyperbolic shape around the regression line.
- This reflects the increasing uncertainty in the mean response as $X_h$ moves farther from $\bar{X}$.
3. **Simultaneous Coverage:**
- The Working-Hotelling band ensures that the true regression line $E(Y) = \beta_0 + \beta_1 X$ lies within the band across all values of $X$ with a specified confidence level (e.g., $95\%$).
#### Analysis of Variance (ANOVA) in Regression
ANOVA in regression decomposes the total variability in the response variable ($Y$) into components attributed to the regression model and residual error. In the context of regression, ANOVA provides a mechanism to assess the fit of the model and test hypotheses about the relationship between $X$ and $Y$.
The **corrected Total Sum of Squares (SSTO)** quantifies the total variation in $Y$:
$$
SSTO = \sum_{i=1}^n (Y_i - \bar{Y})^2,
$$
where $\bar{Y}$ is the mean of the response variable. The term "corrected" refers to the fact that the sum of squares is calculated relative to the mean (i.e., the uncorrected total sum of squares is given by $\sum Y_i^2$)
Using the fitted regression model $\hat{Y}_i = b_0 + b_1 X_i$, we estimate the conditional mean of $Y$ at $X_i$. The total sum of squares can be decomposed as:
$$
\begin{aligned}
\sum_{i=1}^n (Y_i - \bar{Y})^2 &= \sum_{i=1}^n (Y_i - \hat{Y}_i + \hat{Y}_i - \bar{Y})^2 \\
&= \sum_{i=1}^n (Y_i - \hat{Y}_i)^2 + \sum_{i=1}^n (\hat{Y}_i - \bar{Y})^2 + 2 \sum_{i=1}^n (Y_i - \hat{Y}_i)(\hat{Y}_i - \bar{Y}) \\
&= \sum_{i=1}^n (Y_i - \hat{Y}_i)^2 + \sum_{i=1}^n (\hat{Y}_i - \bar{Y})^2
\end{aligned}
$$
- The cross-product term is zero, as shown below.
- This decomposition simplifies to:
$$
SSTO = SSE + SSR,
$$
where:
- $SSE = \sum_{i=1}^n (Y_i - \hat{Y}_i)^2$: Error Sum of Squares (variation unexplained by the model).
- $SSR = \sum_{i=1}^n (\hat{Y}_i - \bar{Y})^2$: Regression Sum of Squares (variation explained by the model), which measure how the conditional mean varies about a central value.
Degrees of freedom are partitioned as:
$$
\begin{aligned}
SSTO &= SSR + SSE \\
(n-1) &= (1) + (n-2) \\
\end{aligned}
$$
------------------------------------------------------------------------
To confirm that the cross-product term is zero:
$$
\begin{aligned}
\sum_{i=1}^n (Y_i - \hat{Y}_i)(\hat{Y}_i - \bar{Y})
&= \sum_{i=1}^{n}(Y_i - \bar{Y} -b_1 (X_i - \bar{X}))(\bar{Y} + b_1 (X_i - \bar{X})-\bar{Y}) \quad \text{(Expand } Y_i - \hat{Y}_i \text{ and } \hat{Y}_i - \bar{Y}\text{)} \\
&=\sum_{i=1}^{n}(Y_i - \bar{Y} -b_1 (X_i - \bar{X}))( b_1 (X_i - \bar{X})) \\
&= b_1 \sum_{i=1}^n (Y_i - \bar{Y})(X_i - \bar{X}) - b_1^2 \sum_{i=1}^n (X_i - \bar{X})^2 \quad \text{(Distribute terms in the product)} \\
&= b_1 \frac{\sum_{i=1}^n (Y_i - \bar{Y})(X_i - \bar{X})}{\sum_{i=1}^n (X_i - \bar{X})^2} \sum_{i=1}^n (X_i - \bar{X})^2 - b_1^2 \sum_{i=1}^n (X_i - \bar{X})^2 \quad \text{(Substitute } b_1 \text{ definition)} \\
&= b_1^2 \sum_{i=1}^n (X_i - \bar{X})^2 - b_1^2 \sum_{i=1}^n (X_i - \bar{X})^2 \\
&= 0
\end{aligned}
$$
------------------------------------------------------------------------
The ANOVA table summarizes the partitioning of variability:
+---------------------+----------------+------------+-------------------------+-----------------------+
| Source of Variation | Sum of Squares | df | Mean Square | $F$ Statistic |
+=====================+================+============+=========================+=======================+
| Regression (Model) | $SSR$ | $1$ | $MSR = \frac{SSR}{1}$ | $F = \frac{MSR}{MSE}$ |
+---------------------+----------------+------------+-------------------------+-----------------------+
| Error | $SSE$ | $n-2$ | $MSE = \frac{SSE}{n-2}$ | |
+---------------------+----------------+------------+-------------------------+-----------------------+
| Total (Corrected) | $SSTO$ | $n-1$ | | |
+---------------------+----------------+------------+-------------------------+-----------------------+
------------------------------------------------------------------------
The expected values of the mean squares are:
$$
\begin{aligned}
E(MSE) &= \sigma^2, \\
E(MSR) &= \sigma^2 + \beta_1^2 \sum_{i=1}^n (X_i - \bar{X})^2.
\end{aligned}
$$
- **If** $\beta_1 = 0$:
- The regression model does not explain any variation in $Y$ beyond the mean, and $E(MSR) = E(MSE) = \sigma^2$.
- This condition corresponds to the null hypothesis, $H_0: \beta_1 = 0$.
- **If** $\beta_1 \neq 0$:
- The regression model explains some variation in $Y$, and $E(MSR) > E(MSE)$.
- The additional term $\beta_1^2 \sum_{i=1}^{n} (X_i - \bar{X})^2$ represents the variance explained by the predictor $X$.
The difference between $E(MSR)$ and $E(MSE)$ allows us to infer whether $\beta_1 \neq 0$ by comparing their ratio.
------------------------------------------------------------------------
Assuming the errors $\epsilon_i$ are independent and identically distributed as $N(0, \sigma^2)$, and under the null hypothesis $H_0: \beta_1 = 0$, we have:
1. The scaled $MSE$ follows a chi-square distribution with $n-2$ degrees of freedom:
$$
\frac{MSE}{\sigma^2} \sim \chi_{n-2}^2.
$$
2. The scaled $MSR$ follows a chi-square distribution with $1$ degree of freedom:
$$
\frac{MSR}{\sigma^2} \sim \chi_{1}^2.
$$
3. These two chi-square random variables are independent.
The ratio of two independent chi-square random variables, scaled by their respective degrees of freedom, follows an $F$-distribution. Therefore, under $H_0$:
$$
F = \frac{MSR}{MSE} \sim F_{1, n-2}.
$$
The $F$-statistic tests whether the regression model provides a significant improvement over the null model (constant $E(Y)$).
The hypotheses for the $F$-test are:
- **Null Hypothesis** ($H_0$): $\beta_1 = 0$ (no relationship between $X$ and $Y$).
- **Alternative Hypothesis** ($H_a$): $\beta_1 \neq 0$ (a significant relationship exists between $X$ and $Y$).
The rejection rule for $H_0$ at significance level $\alpha$ is:
$$
F > F_{1-\alpha;1,n-2},
$$
where $F_{1-\alpha;1,n-2}$ is the critical value from the $F$-distribution with $1$ and $n-2$ degrees of freedom.
1. **If** $F \leq F_{1-\alpha;1,n-2}$:
- Fail to reject $H_0$. There is insufficient evidence to conclude that $X$ significantly explains variation in $Y$.
2. **If** $F > F_{1-\alpha;1,n-2}$:
- Reject $H_0$. There is significant evidence that $X$ explains some of the variation in $Y$.
#### Coefficient of Determination ($R^2$)
The **Coefficient of Determination** ($R^2$) measures how well the linear regression model accounts for the variability in the response variable $Y$. It is defined as:
$$
R^2 = \frac{SSR}{SSTO} = 1 - \frac{SSE}{SSTO},
$$
where:
- $SSR$: Regression Sum of Squares (variation explained by the model).
- $SSTO$: Total Sum of Squares (total variation in $Y$ about its mean).
- $SSE$: Error Sum of Squares (variation unexplained by the model).
------------------------------------------------------------------------
**Properties of** $R^2$
1. **Range**: $$
0 \leq R^2 \leq 1.
$$
- $R^2 = 0$: The model explains none of the variability in $Y$ (e.g., $\beta_1 = 0$).
- $R^2 = 1$: The model explains all the variability in $Y$ (perfect fit).
2. **Proportionate Reduction in Variance**: $R^2$ represents the proportionate reduction in the total variation of $Y$ after fitting the model. It quantifies how much better the model predicts $Y$ compared to simply using $\bar{Y}$.
3. **Potential Misinterpretation**: It is not really correct to say $R^2$ is the "variation in $Y$ explained by $X$." The term "variation explained" assumes a causative or deterministic explanation, which is not always correct. For example:
- $R^2$ shows how much variance in $Y$ is accounted for by the regression model, but it does not imply causation.
- In cases with confounding variables or spurious correlations, $R^2$ can still be high, even if there's no direct causal link between $X$ and $Y$.
------------------------------------------------------------------------
For simple linear regression of $Y$ on $X$:
1. Squared correlation equals $R^2$:
$$
R^2 = r^2,
$$
where $r = \mathrm{corr}(X, Y)$ is the Pearson correlation coefficient.
2. Slope in terms of correlation: The unstandardized slope $b_1$ can be expressed as
$$
b_1 = r \cdot \frac{s_Y}{s_X},
$$
where $s_Y$ and $s_X$ are the sample standard deviations of $Y$ and $X$, respectively. This form makes the scaling effect explicit: if $Y$ has larger spread than $X$, the slope will be larger for the same $r$.
3. Alternative form of $r$:
$$
r = \frac{b_1 s_X}{s_Y}.
$$
If we standardize both $X$ and $Y$ to have mean $0$ and standard deviation $1$ (z-scores), the regression slope equals the correlation:
$$
b_1^{\text{(standardized)}} = r.
$$
This is because:
- Standardization removes units, so the scaling factor $\frac{s_Y}{s_X}$ becomes $1$.
- In this form, the coefficient is *unitless* and symmetric with respect to swapping $X$ and $Y$.
------------------------------------------------------------------------
Symmetry of Correlation vs. Asymmetry of Slopes
- **Correlation**: $r(X,Y) = r(Y,X)$. The correlation is symmetric, meaning the correlation between $X$ and $Y$ is the same as between $Y$ and $X$.
- **Unstandardized slopes**:
- Slope of $Y$ on $X$: $b_1^{Y|X} = r \cdot \frac{s_Y}{s_X}$
- Slope of $X$ on $Y$: $b_1^{X|Y} = r \cdot \frac{s_X}{s_Y}$
These are generally **not equal** unless $s_X = s_Y$.
Intuition
- The correlation measures *strength of association* on a scale from -1 to 1, independent of units.
- The slope measures *rate of change* in the original units: "How much $Y$ changes for a one-unit change in $X$."
- Standardizing removes the influence of measurement units and scale, making the regression coefficient identical to $r$.
- When variables are in different units (e.g., dollars vs. kilograms), unstandardized slopes will differ depending on which variable is treated as the predictor and which as the outcome, but the correlation stays the same.
------------------------------------------------------------------------
#### Lack of Fit in Regression
The **lack of fit** test evaluates whether the chosen regression model adequately captures the relationship between the predictor variable $X$ and the response variable $Y$. When there are repeated observations at specific values of $X$, we can partition the Error Sum of Squares ($SSE$) into two components:
1. **Pure Error**
2. **Lack of Fit**.
Given the observations:
- $Y_{ij}$: The $j$-th replicate for the $i$-th distinct value of $X$,
- $Y_{11}, Y_{21}, \dots, Y_{n_1, 1}$: $n_1$ repeated observations of $X_1$
- $Y_{1c}, Y_{2c}, \dots, Y_{n_c,c}$: $n_c$ repeated observations of $X_c$
- $\bar{Y}_j$: The mean response for replicates at $X_j$,
- $\hat{Y}_{ij}$: The predicted value from the regression model for $X_j$,
the Error Sum of Squares ($SSE$) can be decomposed as:
$$