Linear regression calculator with r², p-value and residuals
This linear regression calculator fits a least-squares line to your data and tells you everything a statistics class or a lab report asks for: slope and intercept, Pearson’s r, r², the standard error of the estimate, standard errors and a 95% confidence interval for the slope, the t statistic and its two-tailed p-value, plus a residual for every point. A scatter plot with the fitted line updates as you type.
Paste data straight from a spreadsheet, a CSV export or a lab notebook — commas, tabs, semicolons and spaces all work, header rows are skipped, and a three-column table uses its last two columns as x and y. Switch the model to quadratic or cubic when the points clearly curve, type any x to predict y, and copy the equation as plain text, LaTeX or a residuals CSV.
How to use the Linear Regression Calculator
- Paste your pairs into Data, one pair per line (for example
3, 61). A single column of numbers is treated as y values with x = 1, 2, 3… - Keep Model on Linear for a straight line, or choose Quadratic or Cubic for curved data.
- Read the fitted equation in the result box with r² and, for the linear model, r.
- Type a value in Predict y for x = to see the predicted y on the line and as a marked point on the plot.
- Open Details, standard errors and residuals for the t statistic, p-value, confidence interval and the per-point residual table.
- Use Copy equation, Copy LaTeX, Copy residuals CSV or Download SVG to take the result into a report.
Linear Regression Calculator features
Full inferential output
Standard errors of slope and intercept, a 95% confidence interval using the t distribution, and an exact two-tailed p-value from the regularised incomplete beta function — not a lookup table.
Flexible input
Comma, tab, semicolon or space separated pairs, quoted CSV headers, three-column tables and single-column y lists are all recognised automatically.
Polynomial fits
Quadratic (degree 2) and cubic (degree 3) least-squares fits with r² and adjusted r², solved on centred, scaled x values so large numbers such as years do not lose precision.
Residual table
Every point shows its fitted value ŷ and residual y − ŷ, which is the quickest way to spot an outlier or a curved pattern a straight line is missing.
Live scatter plot
An SVG chart with nice axis ticks, the fitted line or curve and your prediction point, downloadable as a vector file.
Copy-ready output
The equation as text or LaTeX (\hat{y} = …) and the residuals as CSV for a spreadsheet.
How the least-squares line is calculated
Ordinary least squares chooses the slope b and intercept a that minimise the sum of squared vertical distances between the points and the line. With the sums Sxx = Σ(x − x̄)² and Sxy = Σ(x − x̄)(y − ȳ), the formulas are b = Sxy / Sxx and a = ȳ − b·x̄. Pearson’s correlation is r = Sxy / √(Sxx·Syy), and r² is the share of the variation in y explained by the line.
The standard error of the estimate is s = √(SSE / (n − 2)), the standard error of the slope is SE(b) = s / √Sxx, and the test statistic t = b / SE(b) follows a t distribution with n − 2 degrees of freedom when there is no real relationship. The p-value is the probability of a t that extreme or more; below 0.05 is the usual threshold for calling the slope significant.
Worked example
For the points (1, 2), (2, 4) and (3, 6.1): x̄ = 2 and ȳ = 4.0333. Sxx = (−1)² + 0 + 1² = 2 and Sxy = (−1)(−2.0333) + 0 + (1)(2.0667) = 4.1, so the slope is 4.1 / 2 = 2.05 and the intercept is 4.0333 − 2.05 × 2 = −0.0667. The fitted line ŷ = −0.0667 + 2.05x gives r = 0.9999 and r² = 0.9998 — almost all the variation in y follows x. With only one degree of freedom the p-value is about 0.009, a reminder that three points cannot prove much.
| x | y | ŷ | Residual |
|---|---|---|---|
| 1 | 2 | 1.9833 | 0.0167 |
| 2 | 4 | 4.0333 | −0.0333 |
| 3 | 6.1 | 6.0833 | 0.0167 |
When to use a quadratic or cubic fit
If the residuals form a clear arch or S-shape, a straight line is the wrong model. The quadratic option fits y = a + bx + cx² and the cubic option adds a dx³ term; both are still linear least squares, solved with the normal equations. Compare adjusted r² rather than r², because r² can only go up when you add terms. A polynomial that passes through every point is usually overfitting — it will predict badly outside the data range, so avoid extrapolating far beyond your smallest and largest x.
For data that needs a distribution rather than a line, the normal distribution calculator and standard deviation calculator cover the descriptive side, and you can plot any fitted equation against other curves in the function grapher.
Linear Regression Calculator FAQ
How do I paste data into the linear regression calculator?
Copy two columns from Excel, Google Sheets or a CSV file and paste them in. Tabs, commas, semicolons and spaces are all accepted, and a text header row such as “hours,score” is ignored.
What does r² mean?
r² is the proportion of the variance in y that the fitted model explains. 0.90 means 90% of the spread in y is accounted for by x; the rest is noise or other factors.
How is the p-value calculated?
From the t statistic b / SE(b) with n − 2 degrees of freedom, using the regularised incomplete beta function to get the exact two-tailed probability — the same approach as statistical software, not an approximate table.
Why does the calculator say it needs more points?
A straight line needs at least three points to estimate a standard error (two points always fit perfectly), a quadratic needs four and a cubic five. You also need at least degree + 1 distinct x values.
Can I use dates or years as x?
Yes. Enter them as numbers (2019, 2020…). The calculation centres and scales x internally, so large values do not cause rounding problems even in the cubic model.
Is linear regression the same as correlation?
They are related but different: correlation (r) measures how tightly points follow a straight line and is symmetric in x and y; regression gives the actual line for predicting y from x, so swapping the columns changes the slope.