Skip to main content
HSCalculadora

Linear Regression Calculator

Fit a best-fit line and correlation to paired data.

Comma-separated

Comma-separated, same count as X

Results update as you type.

Slope (m)
—
Intercept (b)—
Correlation (r)—

How it works

Linear regression finds the single straight line that best summarises the relationship between two variables, and this calculator computes it from your paired data using the least-squares method. You enter a list of x values and the matching list of y values, and it returns the slope of the best-fit line, the y-intercept, and the correlation coefficient r. The slope tells you how much y changes on average for each one-unit increase in x, while the intercept is the predicted y when x is zero. Together they give the equation of the line, y equals slope times x plus intercept, which you can use to predict new values or to describe a trend. The correlation coefficient measures how tightly the points cluster around that line: a value near plus one means a strong upward relationship, near minus one a strong downward one, and near zero little linear relationship at all. Scientists fitting experimental data, economists studying how one indicator moves with another, and students in statistics courses all rely on regression. The least-squares line is the same one produced by spreadsheet trendlines and statistical software, computed here instantly from the sums of your data.

Formula

m = (nΣxy − ΣxΣy) / (nΣx² − (Σx)²); b = (Σy − mΣx) / n

Least-squares regression finds the straight line that minimises the sum of the squared vertical gaps between the data points and the line. The slope is the sample covariance of x and y divided by the variance of x, computed here from the sums of x, y, xy and x squared. The intercept places that line so it passes through the mean point. The correlation coefficient r rescales the same covariance to the range minus one to one.

Source:Ordinary least squares regression

We review all our tools from time to time to ensure accuracy.

Worked example

X values:1, 2, 3, 4Y values:3, 5, 7, 9
Points lie exactly on y = 2x + 1, so slope = 2, intercept = 1, r = 1.

How to use this calculator

  1. 1

    Enter your values

    Enter x values and y values.

  2. 2

    Adjust the options

    Fine-tune any options to match your situation.

  3. 3

    Read your result

    Slope (m) updates instantly as you type — no button to press.

Frequently asked questions

What does linear regression do?

Linear regression fits the straight line that comes closest to a set of paired data points, giving you an equation that describes how one variable depends on another. It produces a slope and an intercept, which together let you predict the y value for any x. It is one of the most widely used techniques in statistics, science, and forecasting for summarising trends.

What is the least-squares method?

The least-squares method chooses the line that makes the total of the squared vertical distances between the points and the line as small as possible. Squaring the gaps prevents positive and negative errors from cancelling and penalises large misses more heavily. The resulting line is unique and passes through the average of the x values and the average of the y values.

What does the correlation coefficient r mean?

The correlation coefficient r measures the strength and direction of the linear relationship on a scale from minus one to plus one. Values near plus one indicate points that rise together in a tight line, values near minus one indicate a tight falling line, and values near zero indicate little or no linear pattern. It does not, however, imply that one variable causes the other.

How many data points do I need?

You need at least two points to define a line, and this calculator requires a minimum of two matched pairs. In practice, more points give a more reliable and meaningful fit, because two points always lie perfectly on a line regardless of any real relationship. A handful of well-spread points reveals a trend far more convincingly than the bare minimum.

Does a strong correlation prove causation?

No. A high correlation shows that two variables move together, but it does not establish that one causes the other. The link could be coincidental, driven by a third hidden factor, or run in the opposite direction. Regression describes and predicts relationships, but demonstrating cause requires controlled experiments or careful reasoning beyond the numbers themselves.