What is Regression Analysis?
In the 1880s, British scientist Francis Galton realized something, that at the time was groundbreaking. The children of tall parents were themselves tall. And the children of short parents were also short. In a paper he published in 1886, he called this observation “regression towards mediocrity.”
Galton’s word described a pattern in data, wich is a bit unrelated to the topic of this post. But the line he drew became widely known as the regression line. The method had nothing to do with fitting the least-squares we now associate with regression. Yet, the name stuck around for well over a century.
Today, regression analysis is one of the most widely used technique in statistics.
The methodology is simple. The idea is to see how one or more “input” variable affects a single “output” variable.
It is a simple method and widely used in so many applications: estimate patient’s risk of readmission; security teams use it to predict how many alerts will land in queue the following day; retailers use to forecast demand; and economists use it to measure what drives waves.
Today, there are well over 30 different regression methods. In this post, I want to discuss the core idea, and then cover the five common types.
Foundational Concept
Imagine an apartment complex trying to understand what affects showings. The dependent variable being apartment showing (Y) and the independent variable (X) could be many things. Let’s say for this problem, we are looking at the weather. On rainy days apartment showings tend to drop because people prefer not getting wet.
Every regression is the same three ingredients:
The dependent variable (Y): This this the outcome you want to explain or predict. The number of showings, how many failed logins per hour, the total number of sales.
The independent variable (X): These are the inputs. The predictors or features, such as the weather, age, dosage, time of the day.
The coefficients: the numbers the model learns. Each one tells how much Y moves when its X moves.
Imagine a scatter plot of dots. When drawing a line through the chart, it will not hit every dot. Some are going to be above, others below. This gap between the actual value and the predicted value is called residual.
Once you have the line drawn across the chart, you can explain how strongly is weather related to apartment showings or predict what blood pressure you can expect for a 55-year-old.
One of the most common issues in regression is correlation and causation.
Correlation is not Causation
One thing to remember is that correlation is not causation. I know, it is a cliche; but it is also a statistic mantra.
Correlation is when the variables are directly connected and when X goes up, Y goes up or down. Causation argues that just because two variables are linked doesn’t mean one causes the other.
A cardinal rule in statistics is to always explore relationships. However, correlation should never be assumed. Just because two variables move in the same direction, doesn’t mean one causes the other.
For instance, as community energy grids experience spike in air conditining usage, local pharmacies sunburn cream sales increase drastically. The third variable, known as hidden confounder, is hot sunny wheater, which independently drives people to run their AC and spend time outside getting burned.
One thing to remember when working with regression: prove if it is causation or correlation is not required. So, every single variable analyzed could be driven by a hidden cofounder. However it is critical to keep that in mind when drawing conclusions. Regression can never answer that question.
A correlation can be quantified by calculating the correlation efficient, which is represented by \(r\).
\(r\) = -1 indicates a perfect negative correlation.
\(r\) = 1 indicates a perfect positive correlation
\(r\) = 0 indicates no correlation.
Common Types of Regression
There are multiple types of regression. For the purposes of this article, I will cover four most common types.
Simple Linear Regression
A simple linear is considered the starting point of machine learning due to its simplicity. It finds the relations between the input data and output data. When using this method, you are only taking two variable into consideration.
\(y = \beta_0 + \beta_1 x + \varepsilon\)
In plain words: \(\beta_0\) is the intercept (the value of y when x is zero). \(\beta_1\) is the slope (how much y changes for each one unit increased in x) and \(\varepsilon\) is the error the line can’t explain.
Suppose a clinic wants to understand how systolic blood pressure relates to age. A fitted model might look like blood pressure = 98 + 0.9 x age. The slope says that on average, each additional year of age is associated with about 0.9 mmHg higher blood pressure.
To find out if the fit is good, the most common summary is R². That is the variation in y that the model explains. An R² of 0.40 means the line account for 40% of the ups and downs of the blood pressure. The other 60% comes from elements that is not included in the model.
Multiple Linear Regression
Outcomes rarely depend on a single factor. Similar to the simple linear regression, the multiple regression maintains the line straight but allows you to use more variables into the equation.
The biggest change here is the coefficients. Each \(\beta\) now means the change in y for a unit in x, holding all predictors constants.
Back to the blood pressure example, now let’s include age, BMI, and sodium intake. Age and BMI tend to rise together, in a simple linear regression, the age slope was quietly absorbing the BMI. Now as separate factors, it gives a much cleaner view of each one.
As more variables are added the more complex the your model is. One common problem is multicollinearity. That is when predictors are strongly related and the model struggles to tell their effect on X.
In a multiple linear regression selecting the right variables becomes the greatest challenge. When enough predictors are added to the model, it will overfit. It becomes extra tricky when adjusted R² penalizes these extra predictors.
Logistic Regression
So far, all of the regression we looked at, predict a number. Logistic regression is designed to answer binary questions. Yes or no. Will this patient be readmitted in the next 30 days? Is this login malicious?
Instead of a straight line with a probability of 1.3 or -0.2, logistic regression uses an S-shaped logistic (sigmoid) function that squeezes every output between 0 and 1.
Its formula is a little more interesting than the other types:
\(p = \frac{1}{1 + e^{-(\beta_0 + \beta_1 x_1 + \dots + \beta_k x_k)}}\)
At its core, in the log-odds (the logit) of event, this model is linear. Odds are p/(1 - p). Taking the log turns that bounded probability into a number that can range freely, which is what makes the linear part work.
In this type of model, raw coefficients are calculated in terms of log-odds. For example, a coefficient might tell you that each prior hospital admission increases the log-odds of readmission by 0.405. But the human brain doesn’t work in log-odds, making the raw number difficult to interpret intuitevily.
To make these numbers meaningful, analysists convert them by calculating the exponent of the coefficient. This transformation turns the raw value into an odds ratio.
An odds ratio acts as a multiplier for the likelihood of an event happening. For instance, the odds ratio for prior admission is 1.5, it means that for every additional admission a patient has, their odds of being readmission are multiplied by 1.5, assuming all other variables in the model are exactly the same.
Each dot on the image above is a patient who either was or wasn’t readmitted; the s-curver turns that yes/no data into a smooth probability that never leaves the 0 to 1 range.
The metrics to measure the how well this model is doing is a little different than the traditional R² as it uses accuracy, precision, recall, and ROC AUC.
Nonlinear Regression
The nonlinear regression is tricky because of polynomial regression, which is curved.
A model is linear if it is linear in its parameters. A model is nonlinear when the parameters sit inside the equation in a nonlinear way, such as exponent or a denominator.
\(y = \frac{V_{max} \, x}{K + x}\)
No amount of adding x² columns can turn that into a straight weighted sum of Vmax and K. Other common nonlinear shapes include exponential growth and decay, logistic growth curvers, and dose response curves that plateau.
Both fitted parameters mean something physical: Vmax is the ceiling the curve approaches, and K is the concentration where the reaction runs at half of that speed.
What changes in practice:
You must choose the equation. Linear regression has one basic form. Nonlinear regression can take infinitely many, so you specify the function, ideally from domain knowledge (biology, physics, pharmacology) rather than by guessing.
Fitting is iterative. There is no closed-form solution. Algorithms such as Gauss–Newton or Levenberg–Marquardt start from initial guesses and refine them step by step until the error stops shrinking.
Starting values matter. Poor starting guesses can make the algorithm fail to converge or settle on a bad answer.
Transforming to linear is tempting but risky. You can sometimes rearrange a nonlinear equation into a linear one (a log transform, for instance). That distorts the errors and usually gives a worse fit. It is better used to generate starting values for a true nonlinear fit.
Assumptions to Keep in Mind
The output of regression models will always be numbers. Whether those numbers mean anything depends on a few assumptions. For linear models (simple and multiple), these are five checks:
Assumption |
What it means |
How to check it |
|---|---|---|
Linearity |
The relantionship between two predictors and outcome is linear in the parameters |
Residual vs fitted plot should look random band |
Independence |
Errors from one observation don’t influence another |
Think about how the data was collected in Watson test for time series |
Homoscedasticity |
Residuals have roughly constant spread at every level of predictions |
Residual plot should not fan out |
Normality of residuals |
Errors are roughly normally distributed |
Q-Q plot; Shapiro-Wilk test |
No multicollinearity |
Predictors are not highly correlated with each other |
Variance inflation factor (VIF) |
Conclusion
Which model should you use? This question always fits right along with the No-Free-Lunch theorem no one model is good for everything. The key is to identify which model works best depending on your data and needs.
A personal preference, I always start with the simplest model, then move up to something more robust if necessary.
No comments yet. Be the first.