
Linear regression: types, least squares and limitations
Linear regression is a statistical process with which you demonstrate and quantify a (usually) linear relationship between two quantities. Used properly it is a powerful tool for examining data and predicting; used carelessly it is just as suitable for manipulating outcomes. Everything depends on knowing the preconditions.
Key takeaways
- Linear regression calculates the straight line that lies as close as possible to the measurement points: the dependent quantity (y-axis) as a function of the independent quantity (x-axis).
- With the least squares principle the sum of the squared vertical deviations from the line is as small as possible.
- The correlation coefficient r shows how well the points lie on the line: 1 or −1 is perfect, 0 means no relationship.
- If the outcome is yes/no or bounded between 0% and 100%, use logistic regression instead.
- A line can be calculated through any set of points. Anscombe’s quartet shows four very different data sets with exactly the same line: always look at the scatter plot.
What is linear regression?
Linear regression is a statistical process that demonstrates and quantifies a linear relationship between an independent quantity and a dependent quantity by calculating the best-fitting straight line through the measurement points.
You choose one quantity, the independent one, which is on the x-axis. The other quantity is determined by it: the dependent quantity on the y-axis. Linear regression is one of the methods of predictive analytics: when the line rises or falls, you have a (simple) predictive model.
Linear regression and the least squares principle
With linear regression you can demonstrate a relationship between two or more variables, for example the outside temperature and the number of ice skates sold, or someone’s age and the number of films they watch. You plot the measurements in a coordinate system and calculate a straight line, for instance on the basis of the least squares principle: the line for which the total of the squared deviations from the line, measured vertically, is the smallest.
Simple, multiple and logistic regression
Linear versus logistic regression
The type of outcome determines the choice.
Linear regression
Logistic regression
Outcome
A number without bounds
Yes/no or a probability
Shape
Straight line
S-shaped curve
Example
Skates sold by temperature
Pass probability by study time
Risk
Values outside the possible range
Harder to interpret
Simple linear regression has one dependent variable (the skates) and one independent variable (the temperature). Multiple linear regression has several independent variables, for example temperature and country; these are called explanatory or predictive variables.
In quite a few cases you cannot or do not want to apply linear regression, because the dependent variable has a fixed outcome (yes/no) or a lower and upper limit. Take the number of study minutes per student and the probability of passing the exam, which lies between 0% and 100%: you cannot have a 101% or −10% chance. Nor is the relationship a continuous straight line: between 0 and 25 study minutes the pass probability is very low (at most 10%), between 25 and 50 minutes it rises sharply to 40%, and beyond that the increase levels off. A straight line overestimates the probability at one end and underestimates it at the other. Here you want a curve made with logistic regression, which predicts far more accurately.
Where the name comes from: Francis Galton
The term regression arose when the scientist Francis Galton, a half-cousin of Charles Darwin, discovered in the nineteenth century a pattern in the offspring of tall people: they become shorter over generations until they reach the average height. He called this effect regression because the decrease in height took place more or less linearly. Later researchers adopted the name and the statistics, but applied them to other measurements, including ones that show an increase.
Example: the stretching of a spring
The operation of linear regression is excellently illustrated by a simple physics experiment in which the extension x of a spring is measured as a function of the gravitational force Fz on a block hanging from it. The force depends directly on the mass m of the block according to Fz = m·g, in which g = 9.81 m/s² is the gravitational acceleration. You choose the mass, which determines the force, and measure the extension for different values.

The numbers show that the extension increases as the force increases, but not immediately whether there is a regularity. Plotted in a diagram, a regularity begins to emerge: possibly x = C1·Fz + C2, with C1 and C2 constants. Two questions then have to be answered:
- How do you find the most suitable straight line through the measurement points, in other words the values of C1 and C2?
- How reliable is the equation found, in other words how accurately can you calculate x from Fz and vice versa?
In the pre-computer era the line was fitted between the measurement points with a ruler as well as possible, keeping the average distance between points and line as small as possible. The arithmetic is not difficult, but so time-consuming that an experienced calculator needed about a whole day for one diagram. Today every spreadsheet knows the procedure: determining the line is a purely mathematical operation that can in principle be carried out on any set of measurement data.
How good is the line? The correlation coefficient
However beautiful a diagram looks, the question about the quality of the approximation remains. In practice this is solved by determining the correlation coefficient r, which indicates how well the measurement points lie on the calculated line: r = 1 for the perfect rising line, r = −1 for the perfect falling line and r = 0 if there is no relationship.
What are the limitations?
That the procedure can be applied to any set of data is its strength and at the same time its Achilles heel. The data must meet certain conditions:
- The independent quantity has (almost) no spread: its value is known exactly.
- The dependent quantity is a linear combination of the independent quantity.
- The variance in the dependent quantity is independent of the size of the independent quantity.
Adjustments in the calculation method make it possible to include spread in the independent quantity (condition 1). That does not apply to the other conditions. If one of them is not met, linear regression is not applicable to the data, gives no reliable outcomes, or the problem is not properly described.
Anscombe’s quartet: four sets, one line
Even if the data clearly show no linear relationship, a line can still be calculated. Very illustrative is Anscombe’s quartet, developed in 1973 by the English statistician Frank Anscombe: four different sets of measurement points (normal, curved, with a peak, clustered) that end up with exactly the same line after linear regression. The other key figures are identical too:
- Mean of the x-values: 9
- Variance of the x-values: 11
- Mean of the y-values: 7.50
- Variance of the y-values: about 4.12
- Correlation coefficient: 0.816
- Regression line: y = 3.00 + 0.500x
Anyone who only looks at the numbers sees no difference and will consider the four sets equivalent. A look at the scatter plots quickly shows that in at least two of the four cases the calculated line has no meaning.
Shortening the axes
Shortening the axes of a diagram, or working with only part of the data, can suggest that data are easy to “linearise” when the opposite is true. This applies in particular when part of the data is used to derive a relationship that is then used to categorise the remaining or incomplete data, as happens in techniques such as nearest neighbor. By playing with the scale and the values presented, a relationship can be suggested while the data in fact say something else. Linear regression is regularly tampered with for the sole purpose of presenting a ‘desired’ answer.
How Diamond Decisions applies linear regression
Diamond Decisions likes to start with regression because the result fits in one sentence: one unit more of this gives so much more of that. After inspiration, business modeling determines which relationship matters for which decision, data analytics checks the preconditions and the scatter plot before any line is drawn, and the decision makers get the uncertainty alongside the forecast.
Talk to the author
Herman van DellenDiamond Decisions
Discuss your question with Herman
Tell us which decision needs to improve. In a no-obligation conversation we show you where your data delivers the most.
Schedule an introduction →Step 3 of our approach
Diamond Data Analytics
A data warehouse that starts with your most important decisions and is ready for conversational AI: a working prototype within 24 hours.
Explore Data Analytics →Frequently asked questions
01
What is linear regression?
A statistical method that calculates the best-fitting straight line through measurement points, to demonstrate and quantify the relationship between an independent and a dependent quantity and to predict with it.
02
What is the least squares principle?
The line is chosen so that the sum of the squared vertical distances between the measurement points and the line is as small as possible.
03
What is the difference between linear and logistic regression?
Linear regression predicts a number on a continuous scale with a straight line. Logistic regression predicts a probability or a yes/no outcome with an S-shaped curve that stays between 0% and 100%.
04
What does Anscombe’s quartet teach?
That four completely different data sets can have the same mean, variance, correlation and regression line. Numbers alone are not enough: always look at the scatter plot.
05
Can an SME use linear regression?
Yes, it is available in every spreadsheet. It works well for questions such as how revenue relates to advertising spend or how energy use relates to production volume, provided you check the scatter plot and do not extrapolate far beyond the measured range.
Further reading
Sources
- Wikipedia: Francis Galton.
- Wikipedia: Frank Anscombe (Anscombe’s quartet, 1973).
About the author
About Diamond Decisions
Diamond Decisions helps organizations become better by enabling better decisions. We don’t start with data, dashboards or AI, but with the decision that needs to improve, and work back from there to KPIs, data and technology. We do that in four steps: inspiration and alignment, business modeling, analytics and data platform and data-driven decision makers. That way BI and AI don’t remain an IT project, but deliver value every day.

