Introduction to Simple Linear Regression

  • Simple Linear Regression is a statistical method used to model the relationship between two continuous variables, where one variable is considered as the predictor or independent variable, and the other is considered as the response or dependent variable.

  • It assumes that there is a linear relationship between the predictor variable \(X\) and the response variable \(Y\).

Mathematical Representation

The simple linear regression model can be represented as:

\[ Y = \beta_0 + \beta_1 X + \varepsilon \]

where: - \(Y\) is the response variable. - \(X\) is the predictor variable. - \(\beta_0\) is the intercept. - \(\beta_1\) is the slope. - \(\varepsilon\) is the error term.

Example 1: Predicting House Prices

We want to predict house prices based on their size (in square feet). We collect data on house sizes and their corresponding prices.

Let’s assume the simple linear regression model:

\[ \text{Price} = \beta_0 + \beta_1 \times \text{Size} + \varepsilon \]

We want to estimate the coefficients \(\beta_0\) and \(\beta_1\) from the data.

Estimating Coefficients

To estimate the coefficients \(\beta_0\) and \(\beta_1\), we use the method of least squares. The goal is to minimize the sum of squared differences between the observed and predicted values of the response variable.

The estimated coefficients are given by:

\[ \hat{\beta}_1 = \frac{\sum_{i=1}^{n} (X_i - \bar{X})(Y_i - \bar{Y})}{\sum_{i=1}^{n} (X_i - \bar{X})^2} \]

\[ \hat{\beta}_0 = \bar{Y} - \hat{\beta}_1 \bar{X} \]

where \(\bar{X}\) and \(\bar{Y}\) are the sample means of the predictor and response variables, respectively.

Plotting the Regression Line

Let’s visualize the relationship between house size and price using a scatter plot with the fitted regression line.

## `geom_smooth()` using formula = 'y ~ x'

Example 2: Predicting Exam Scores

Suppose we want to predict students’ exam scores based on the number of hours they studied. We collect data on students’ study hours and their corresponding exam scores.

Let’s assume the simple linear regression model:

\[ \text{Exam Score} = \beta_0 + \beta_1 \times \text{Study Hours} + \varepsilon \]

We want to estimate the coefficients \(\beta_0\) and \(\beta_1\) from the data.

Plotting the Regression Line

Let’s visualize the relationship between study hours and exam scores using a scatter plot with the fitted regression line.

## `geom_smooth()` using formula = 'y ~ x'