Linear Regression
Learn how to find the line of best fit for data and use it to make predictions.
Definition
- is the slope (how much changes for each unit increase in )
- is the y-intercept (the value of when )
Try it now
Worked Examples
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
→ ,
Calculate slope using the formula
Numerator: Denominator: →
Calculate y-intercept
→
Write the regression equation
→ Regression line:
Answer: The regression line is . This means for every 1°C increase in temperature, iced coffee sales increase by about 2.5 units.
Common Mistakes
Assuming the regression line passes through all data points
Why it's wrong: 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.
Using the regression equation for extrapolation far beyond the data range
Why it's wrong: 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.
Confusing correlation with causation
Why it's wrong: 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.
Forgetting to check if a linear model is appropriate
Why it's wrong: 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.
Interactive Visual
Linear Function Explorer
| x | y |
|---|---|
| -2 | -2 |
| -1 | -1 |
| 0 | 0 |
| 1 | 1 |
| 2 | 2 |
Interactive Sandbox
Interactive Grapher
Try these examples:
y = 2x + 1
m=2, b=1
Expression Calculator
Try these:
History
No calculations yet
Practice Problems
16 problemsWhat does the slope in a regression line represent?
Why It Matters
- Business: Predict sales based on advertising spending or price changes
- Science: Model relationships between variables in experiments
- Medicine: Predict patient outcomes based on treatment data
- Economics: Forecast economic indicators based on historical trends
- Sports: Analyze player performance and predict future statistics
Real World Applications
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.
Example:
If where is square meters and is price in euros, a 100 m² apartment would cost about 150(100) + 50000 = 65000 euros.
A real estate model shows: Price = 200x + 30000 (where x = square meters).
What price would you predict for a 120 m² apartment?
Step 1: Write the mathematical expression
Substitute into the equation:
Fuel Efficiency Analysis
Automotive engineers use regression to understand how car weight affects fuel consumption.
Example:
If fuel consumption (L/100km) = 0.004 × weight (kg) + 2, a 1500 kg car would use 0.004(1500) + 2 = 8 L/100km.
A car manufacturer's data shows: Fuel = 0.005w + 1.5 (where w = weight in kg).
Predict fuel consumption for a 1200 kg vehicle.
Step 1: Write the mathematical expression
Calculate:
Business Sales Forecasting
Companies use regression to predict future sales based on advertising spending, helping them allocate marketing budgets effectively.
Example:
If monthly sales = 3 × ad spending + 10000, spending 5000 euros on ads predicts sales of 3(5000) + 10000 = 25000 euros.
A company's model: Sales = 4 × AdBudget + 8000.
If they spend 3000 euros on advertising, what sales can they expect?
Step 1: Write the mathematical expression
Calculate predicted sales:
Key Takeaways
- 1Linear regression finds the line that best fits a set of data points
- 2The regression line equation is where is slope and is y-intercept
- 3Slope tells you how much changes for each unit increase in
- 4The y-intercept is the predicted value of when
- 5Use regression to make predictions, but be cautious about extrapolating far beyond your data
Frequently Asked Questions
Glossary
- Linear regression
- A statistical method for finding the straight line that best fits a set of data points
- Line of best fit
- The regression line that minimizes the sum of squared residuals
- Slope
- The rate of change; how much increases for each unit increase in
- Y-intercept
- The value of when ; where the line crosses the y-axis
- Residual
- The difference between an actual data point and its predicted value on the regression line
- Least squares
- The method that finds the line minimizing the sum of squared residuals
- Extrapolation
- Using a regression equation to predict values outside the range of the original data
Formula Card
Regression Line
The equation of the line of best fit where m is slope and b is y-intercept
Slope Formula
Calculate the slope from data points using means and deviations
Y-Intercept
Calculate the y-intercept using the slope and the means of x and y
Residual
The difference between actual and predicted values for each point