No history yet

Linear Regression

Drawing a Line Through Data

Linear regression is a way to find a straight-line relationship between two or more variables. Imagine you're trying to predict a house's price based on its size. You'd collect data on many houses, noting their square footage and selling price. Linear regression helps you draw the best possible straight line through those data points on a graph.

The goal is to model the relationship between a dependent variable (the one you want to predict, like house price) and one or more independent variables (the factors used for prediction, like square footage). By finding the line that best fits the data, we can make educated guesses about new, unseen data.

Lesson image

The relationship is captured in a simple equation. For one independent variable, it looks like this:

y=β0+β1x+ϵy = \beta_0 + \beta_1x + \epsilon

The model calculates the optimal values for the intercept (eta_0) and the slope (eta_1) to minimize the overall distance between the line and the actual data points. This process is often called finding the "line of best fit."

The Rules of the Road

For a linear regression model to be accurate and reliable, the data needs to follow a few key rules, often remembered by the acronym LINE:

Linearity: The underlying relationship between the independent and dependent variables is linear. Independence: The errors (or residuals—the differences between actual and predicted values) are independent of each other. Normality: The errors are normally distributed. Their values should cluster around zero, forming a bell-shaped curve. Equal Variance (Homoscedasticity): The errors have constant variance across all levels of the independent variable. In other words, the data points should be scattered evenly around the regression line.

If these assumptions aren't met, the model's predictions might be inaccurate or misleading. For example, if the relationship isn't linear, trying to fit a straight line to a curve will produce a poor model.

Prediction and Understanding

Linear regression has two main jobs: prediction and inference.

Prediction is about forecasting. Once we've built a model that predicts house prices from square footage, we can plug in the square footage of a new house to estimate its selling price. If our model shows that for every extra square foot, the price increases by $200, we can make a specific price prediction.

Inference is about understanding the relationship between variables. The slope coefficient (eta_1) is crucial here. It tells us the direction and strength of the relationship. A positive slope means that as the independent variable increases, the dependent variable tends to increase too. By testing the statistical significance of this coefficient, we can determine if the relationship is likely real or just due to chance.

Limitations and Challenges

Linear regression is powerful, but it's not perfect. It's sensitive to outliers, which are data points that fall far from the rest of the data. A single outlier can dramatically pull the regression line towards it, distorting the results.

Another issue is multicollinearity. This happens in models with multiple independent variables, where two or more of those variables are highly correlated with each other. For instance, if we're predicting a person's weight using both their height in inches and height in centimeters, the model will struggle to figure out the individual importance of each variable because they provide redundant information.

Finally, it's critical to remember that regression identifies relationships, not causation. Just because two variables are related doesn't mean one causes the other. There could be a third, unobserved factor, called a confounding variable, that influences both.

Lesson image

For example, ice cream sales and drowning incidents are correlated—both rise in the summer. But eating ice cream doesn't cause drowning. The confounding variable is the hot weather, which leads to both more swimming and more ice cream consumption.

Quiz Questions 1/6

What is the primary goal of linear regression?

Quiz Questions 2/6

In the linear regression equation Y=β0+β1X+ϵY = \beta_0 + \beta_1X + \epsilon, what does the β1\beta_1 term represent?

Linear regression provides a simple yet effective framework for modeling relationships in data. By understanding how it works and its underlying assumptions, you can use it to uncover insights and make sound predictions.