Linear regression, explained in plain words
Linear regression is a way of drawing the straight line that best fits a set of paired numbers. You have two lists that belong together — hours studied and marks scored, advertising spend and sales, temperature and ice-cream sales — and you want one simple rule that connects them. The regression line is that rule: for any x you put in, it gives you the best straight-line guess for y.
The line has two numbers that define it. The slope tells you how much y moves when x moves by one: a slope of 0.6 means each extra unit of x adds 0.6 to y. The intercept tells you where the line crosses the y-axis, the value of y when x is zero. Together they give the equation y = a + bx, which is the whole model in one short line.
This calculator takes your two lists, works out the slope, the intercept, the correlation coefficient r, and a prediction for any x value you choose. Paste your data in, separated by commas, spaces or new lines, and the results update live. Everything runs in your browser, so your data never leaves your device.
How the slope and intercept are worked out
The method is called least squares, and the idea is simple: of all the straight lines you could draw through your points, pick the one where the squared vertical gaps between the points and the line add up to the smallest total. Squaring stops positive and negative gaps from cancelling each other out, so the line is pulled towards the middle of the cloud of points instead of being dragged to one side.
The slope comes from a single formula: b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)². In words, you multiply each point's distance from the x-mean by its distance from the y-mean, add those products up, and divide by the sum of the squared x-distances. Once you have the slope, the intercept follows from a = ȳ − bx̄, which forces the line to pass through the point (x̄, ȳ), the centre of your data.
The correlation coefficient r measures how tightly the points hug the line. It runs from −1 to +1. A value near +1 means the points rise together almost perfectly; near −1 means they fall together; near 0 means there is no straight-line pattern at all. The formula is r = Σ(x − x̄)(y − ȳ) ÷ √[Σ(x − x̄)² × Σ(y − ȳ)²].
The correlation coefficient r, and what it really says
People read too much into r, so it helps to know exactly what it does and does not say. An r of 0.77, like the default example on this page, means a fairly strong upward pattern: as x grows, y tends to grow, and the points sit reasonably close to the line. It does not mean x causes y. Ice-cream sales and sunburn cases correlate strongly, but both are driven by hot weather, not by each other.
The square of r, written r², has a concrete meaning: it is the share of the variation in y that the line explains. With r = 0.77, r² is about 0.60, so the line accounts for roughly 60% of the ups and downs in y and the other 40% is noise the line cannot see. A low r² does not mean your data is useless — it means a straight line is only part of the story.
Watch out for r on curved data. If y rises steeply and then flattens, the points form a curve and r can come out low even though x predicts y very well. Plot your data first, or at least look at the pairs: if the pattern bends, a straight line is the wrong tool and no value of r will fix it. A standard deviation calculator can help you see how much spread sits in each list before you regress one on the other.
A worked example: predicting y from x
Take the default lists on this page. The x values are 1, 2, 3, 4 and 5, and the y values are 2, 4, 5, 4 and 5. The mean of x is 3 and the mean of y is 4. The products (x − 3)(y − 4) are 4, 0, 0, 0 and 2, which add up to 6. The squared x-distances are 4, 1, 0, 1 and 4, which add up to 10. So the slope is 6 ÷ 10 = 0.6, and the intercept is 4 − 0.6 × 3 = 2.2.
The correlation needs the y-spread too. The squared y-distances are 4, 0, 1, 0 and 1, adding up to 6. So r = 6 ÷ √(10 × 6) = 6 ÷ 7.75 = 0.77. That is a solid positive link. To predict y when x is 6, plug into the line: y = 2.2 + 0.6 × 6 = 2.2 + 3.6 = 5.8. The calculator shows all four numbers — slope 0.6, intercept 2.2, r 0.77 and predicted y 5.8 — the moment you load the page.
Now try a perfect case to see what r = 1 looks like. With x as 10, 20 and 30 and y as 15, 25 and 35, every point sits exactly on the line y = 5 + x. The slope is 1, the intercept is 5, r is 1, and the prediction at x = 40 is 45. Real data is never this tidy, which is why the first example, with its r of 0.77, is the more honest picture of how regression works in practice.
Where linear regression is used every day
In business, regression turns past numbers into forecasts. A shop plots daily advertising spend against daily sales, fits a line, and reads off what an extra ₹10,000 of ads is likely to bring in. A sales manager uses it to set targets: if the line says 100 calls produce about 12 orders, the team knows what a week of calls should deliver. The prediction is a guide, not a promise, but it beats guessing.
In science and medicine, regression separates a real effect from background noise. A researcher plots drug dose against blood pressure drop and checks whether the slope is clearly different from zero. In farming, yield is plotted against rainfall or fertiliser to find how much of each extra kilogram actually pays. In each case the slope is the finding — the number that says how much one thing moves when the other moves.
In school and college, regression is the first statistics tool students meet, because it needs nothing more than two lists and a few sums. It sits next to the average calculator in most courses: the average tells you where one list sits, and regression tells you how two lists move together. Once you can fit a line, you can read most charts in a newspaper with a much sharper eye.
Linear regression vs correlation: what is the difference?
Correlation and regression answer different questions, and mixing them up causes real mistakes. Correlation asks only how strongly two things move together, and gives one number, r, between −1 and +1. It is symmetric: the correlation of x with y is the same as the correlation of y with x. It says nothing about how much y changes per unit of x.
Regression goes further and builds a prediction rule. It is not symmetric: regressing y on x gives a different line from regressing x on y, because each one minimises the gaps in a different direction. The slope has units — marks per hour studied, sales per rupee of advertising — while r has no units at all. That is why a slope of 0.6 means something concrete and an r of 0.77 means something general.
Use correlation when you want a quick sense of whether two things move together. Use regression when you want to predict one from the other, or to quote the size of the effect in real units. A probability calculator can then help you think about the chance of a value landing far from the line, once you know how much scatter sits around it.
Mistakes that spoil a regression
The first mistake is reading cause into a correlation. A strong r proves a pattern, not a mechanism. Two things can rise together because a third thing drives both, because of a trend over time, or by pure chance in a small sample. Before you claim x causes y, you need a reason that lives outside the numbers.
The second mistake is predicting far outside the data. The line is fitted to x values between 1 and 5 in the default example, so a prediction at x = 6 is a small step and a prediction at x = 100 is a leap of faith. Straight lines rarely stay straight that far. Extrapolation is where most regression forecasts go wrong, so keep predictions close to the range you actually measured.
The third mistake is feeding the calculator mismatched lists — five x values and four y values, or a stray word mixed in with the numbers. The calculator needs pairs, so the two lists must be the same length and each must have at least two numbers; otherwise it shows dashes instead of results. Check the counts first when the results come back blank.
The fourth mistake is ignoring outliers. One wild point can drag the slope a long way, especially in a small sample. If one pair looks nothing like the rest, check whether it is a typing error before you trust the line. And the fifth is fitting a line to curved data: if the points bend, the straight line will be wrong at both ends even if r looks respectable. Plot first, regress second.
How to use this linear regression calculator
Paste your x values into the first box and your y values into the second, separated by commas, spaces or one per line — a column copied from a spreadsheet works as it is. Both lists must have the same number of values, and you need at least two pairs. Type the x value you want a prediction for into the third box; the default is 6.
The results update live. The headline number is the slope, with the intercept, the correlation coefficient r and the predicted y shown below it. Read the slope as the change in y for each one-unit change in x, and read r as the strength of the straight-line pattern. If r is close to zero, treat the prediction with suspicion.
Everything runs in your browser. No account, no upload, no data sent anywhere — your numbers never leave your device. Pair it with the variance calculator when you want to see how much of the spread in y the line leaves unexplained, and re-check your lists whenever a result looks surprising: a single mistyped number is the usual cause.