Linear Regression Calculator
Loading calculator...
How to Perform Linear Regression: A Step-by-Step Example
Consider the following dataset that shows the number of hours studied by a student and their final exam scores: (2, 75), (1, 61), (3, 90), (1.5, 62), (4, 88). Let’s walk through the steps to estimate a linear regression model using this dataset.
Step 1: Plot the Data
First, we'll plot the data to assess the relationship between between a student’s study hours and their exam scores:
The scatterplot shows a positive linear relationship between the student’s study hours and their exam scores. As study time increases, exam scores tend to increase as well, suggesting that a simple linear regression model is appropriate for this data.
Step 2: Calculate the Slope, \( \beta_1 \)
To calculate the slope, we'll first need to find the means of \( X \) and \( Y \):
- Mean of \( X \): \( \bar{X} \) = \( \frac{2 + 1 + 3 + 1.5 + 4}{5} = 2.3 \)
- Mean of \( Y \): \( \bar{Y} \) = \( \frac{75 + 61 + 90 + 62 + 88}{5} = 75.2 \)
Then, we can calculate the slope, \( \beta_1 \):
$$ \begin{aligned} \beta_1 &= \frac{\sum (X_i - \bar{X})(Y_i - \bar{Y})}{\sum (X_i - \bar{X})^2} = \\[0.8em] &= \frac{ (X_1 - \bar{X})(Y_1 - \bar{Y}) + (X_2 - \bar{X})(Y_2 - \bar{Y}) + (X_3 - \bar{X})(Y_3 - \bar{Y}) + (X_4 - \bar{X})(Y_4 - \bar{Y}) + (X_5 - \bar{X})(Y_5 - \bar{Y}) }{ (X_1 - \bar{X})^2 + (X_2 - \bar{X})^2 + (X_3 - \bar{X})^2 + (X_4 - \bar{X})^2 + (X_5 - \bar{X})^2 } = \\[0.8em] &= \frac{ (2 - 2.3)(75 - 75.2) + (1 - 2.3)(61 - 75.2) + (3 - 2.3)(90 - 75.2) + (1.5 - 2.3)(62 - 75.2) + (4 - 2.3)(88 - 75.2) }{ (2 - 2.3)^2 + (1 - 2.3)^2 + (3 - 2.3)^2 + (1.5 - 2.3)^2 + (4 - 2.3)^2 } = \\[0.8em] &= \frac{ (-0.3)(-0.2) + (-1.3)(-14.2) + (0.7)(14.8) + (-0.8)(-13.2) + (1.7)(12.8) }{ 0.09 + 1.69 + 0.49 + 0.64 + 2.89 } = \\[0.8em] &= \frac{ 0.06 + 18.46 + 10.36 + 10.56 + 21.76 }{ 5.8 } = \\[0.8em] &= \frac{61.2}{5.8} \approx 10.55 \end{aligned} $$
Step 4: Write the Regression Equation
The linear regression equation is:
$$ Y = \beta_0 + \beta_1X = 50.93 + 10.55X $$
In this equation, the intercept of 50.93 indicates that a student who studies zero hours is expected to score 50.93% on the final exam. The slope of 10.55 indicates that for each additional hour of studying, the expected final exam score is expected to increase by 10.55 percentage points.