Calculating the predictive line using least squares involves the following steps:
- Calculate the mean of the predictor and target variables
- Calculate the slope and intercept of the predictive line
The slope (\(\beta_1\)) and intercept (\(\beta_0\)) are calculated with the following:
\[ \beta_1 = \frac{\sum_{i=1}^{n} (x_i - \bar{x})(y_i - \bar{y})}{\sum_{i=1}^{n} (x_i - \bar{x})^2} \]
\[ \beta_0 = \bar{y} - \beta_1\bar{x} \]
Where: - \(\bar{x}\) and \(\bar{y}\) are the mean values of the independent and dependent variables respectively, - \(n\) is the number of observations.
The goal of the least squares method is to find the values of \(\beta_0\) and \(\beta_1\) that minimize the sum of the squared residuals:
\[ \text{Minimize} \sum_{i=1}^{n} (y_i - (\beta_0 + \beta_1x_i))^2 \]
This results in a line of ‘best fit’ that accurately represents the trend in the data (assuming it is a linear relationship). The function determining line allows predictions of the dependent variable (\(y\)) given a value of the independent variable (\(x\)).