We model the relationship between a response variable \(Y\) and a predictor \(X\):
\[ Y = \beta_0 + \beta_1 X + \varepsilon \]
where:
- \(\beta_0\) is the intercept
- \(\beta_1\) is the slope
- \(\varepsilon\) is random error
2026-02-09
We model the relationship between a response variable \(Y\) and a predictor \(X\):
\[ Y = \beta_0 + \beta_1 X + \varepsilon \]
where:
- \(\beta_0\) is the intercept
- \(\beta_1\) is the slope
- \(\varepsilon\) is random error
The slope estimator is:
\[ \hat{\beta}_1 = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sum (x_i - \bar{x})^2} \]
The intercept estimator is:
\[ \hat{\beta}_0 = \bar{y} - \hat{\beta}_1 \bar{x} \]
For this example, I will generate data with the following command:
set.seed(123) x <- rnorm(100, mean = 10, sd = 2) y <- 3 + 1.5 * x + rnorm(100, sd = 2) data <- data.frame(x, y)