Linear Regression
Finding the Regression Line
A coffee shop tracks daily temperature (°C) and iced coffee sales: | Temperature | Sales | |-------------|-------| | 15 | 20 | | 20 | 35 | | 25 | 45 | | 30 | 60 | | 35 | 70 | Find the equation of the regression line.
Calculate the means: $\bar{x} = \frac{15+20+25+30+35}{5} = 25$ $\bar{y} = \frac{20+35+45+60+70}{5} = 46$ = $\bar{x} = 25$, $\bar{y} = 46$
Calculate slope using the formula: $m = \frac{\sum(x_i - \bar{x})(y_i - \bar{y})}{\sum(x_i - \bar{x})^2}$ Numerator: $(-10)(-26) + (-5)(-11) + (0)(-1) + (5)(14) + (10)(24) = 260 + 55 + 0 + 70 + 240 = 625$ Denominator: $100 + 25 + 0 + 25 + 100 = 250$ = $m = \frac{625}{250} = 2.5$
Calculate y-intercept: $b = \bar{y} - m\bar{x} = 46 - 2.5(25) = 46 - 62.5 = -16.5$ = $b = -16.5$
Write the regression equation: $y = 2.5x - 16.5$ = Regression line: $y = 2.5x - 16.5$
Answer: The regression line is $y = 2.5x - 16.5$. This means for every 1°C increase in temperature, iced coffee sales increase by about 2.5 units.
Making Predictions
Using the regression line $y = 2.5x - 16.5$ from the coffee shop example, predict sales when the temperature is 28°C.
Identify the equation: $y = 2.5x - 16.5$ = Regression equation identified
Substitute the x-value: $y = 2.5(28) - 16.5$ = $y = 2.5 \times 28 - 16.5$
Calculate: $y = 70 - 16.5 = 53.5$ = $y = 53.5$
Answer: The predicted sales at 28°C is approximately 54 iced coffees.
Interpreting Slope and Intercept
A study finds that the regression line relating hours of study ($x$) to exam score ($y$) is $y = 8x + 40$. Interpret the slope and y-intercept.
Identify the slope: $m = 8$ = Slope is 8
Interpret the slope: For each additional hour of study, the exam score increases by 8 points = 8 points per hour of study
Identify the y-intercept: $b = 40$ = Y-intercept is 40
Interpret the y-intercept: When study time is 0 hours, the predicted exam score is 40 = Base score of 40 points
Answer: Slope: Each additional hour of study adds 8 points to the predicted score. Y-intercept: A student who studies 0 hours would score about 40 points (baseline knowledge).
Mistake: Assuming the regression line passes through all data points
Why: The line of best fit minimizes total error but rarely passes through every point. Points above and below the line are normal.
Correct: Understand that the regression line represents the overall trend, not individual data points.
Mistake: Using the regression equation for extrapolation far beyond the data range
Why: The relationship may not hold outside the range of observed data. Predicting far beyond your data can give unrealistic results.
Correct: Be cautious when predicting for x-values far outside your data range. Note when you're extrapolating.
Mistake: Confusing correlation with causation
Why: A strong linear relationship doesn't mean one variable causes changes in the other. There may be other factors involved.
Correct: Use regression to describe relationships and make predictions, but be careful about claiming causation.
Mistake: Forgetting to check if a linear model is appropriate
Why: Not all data follows a linear pattern. Using linear regression on non-linear data gives misleading results.
Correct: Always plot your data first. If the scatter plot shows a curve, linear regression may not be the best choice.
Predicting Housing Prices
Real estate analysts use linear regression to estimate home prices based on features like square footage, number of bedrooms, or distance from city center.
If $y = 150x + 50000$ where $x$ is square meters and $y$ is price in euros, a 100 m² apartment would cost about 150(100) + 50000 = 65000 euros.
Fuel Efficiency Analysis
Automotive engineers use regression to understand how car weight affects fuel consumption.
If fuel consumption (L/100km) = 0.004 × weight (kg) + 2, a 1500 kg car would use 0.004(1500) + 2 = 8 L/100km.
Business Sales Forecasting
Companies use regression to predict future sales based on advertising spending, helping them allocate marketing budgets effectively.
If monthly sales = 3 × ad spending + 10000, spending 5000 euros on ads predicts sales of 3(5000) + 10000 = 25000 euros.
Linear regression finds the line that best fits a set of data points
The regression line equation is $y = mx + b$ where $m$ is slope and $b$ is y-intercept
Slope tells you how much $y$ changes for each unit increase in $x$
The y-intercept is the predicted value of $y$ when $x = 0$
Use regression to make predictions, but be cautious about extrapolating far beyond your data
Q: What if my data doesn't look linear?
A: If your scatter plot shows a curve rather than a straight line, linear regression may not be appropriate. Consider polynomial regression or other non-linear models instead.
Q: Can regression prove that one thing causes another?
A: No. Regression shows relationships (correlations) but cannot prove causation. Two variables might be related because of a third factor, not because one causes the other.
Q: What is a residual?
A: A residual is the difference between an actual data point and the predicted value from the regression line: residual = $y_{actual} - y_{predicted}$. Positive residuals mean the point is above the line; negative means below.
Linear Regression
1 / 12
Linear Regression
Learn how to find the line of best fit for data and use it to make predictions.