Solved.tools — Free Online Calculators & Tools

We use cookies for analytics and advertising. Learn more about our cookie policy

Linear Regression Calculator

Last updated: 17 August 2026

Reviewed by Gavin · Research and drafting assisted by AI

📈 Linear Regression Calculator

Fit an ordinary-least-squares line y = α + β·x to paired X and Y data. Get the slope, intercept, Pearson r, R², standard error of the estimate, standard error of the slope, t-statistic, two-sided p-value, a confidence interval for β, prediction intervals at a chosen x*, full residual diagnostics, and a live scatter plot with the fitted line and its mean-response confidence band.

Paste from Excel / Sheets — comma, space, semicolon, tab, or newline separators all work. 5 parsed.
Must be the same length as X (paired data). 5 parsed.
Used for the CI on β and the prediction interval. Default 95%.
Returns ŷ* and a 95% prediction interval.
Load example:

Fitted regression line

y = 0 + 2·x
Sample size (n)5
Degrees of freedom (n − 2)3
Slope (β)2
Intercept (α)0
Mean of x (x̄)3
Mean of y (ȳ)6
Σ(xᵢ − x̄)²10
Pearson correlation (r)1.0000
R² (coefficient of determination)1.0000
Residual SS (SSres)0
Total SS (SStot)40
Standard error of estimate (s)0
Standard error of slope (SE_β)0
t-statistic for slope
p-value for slope (two-sided)
95% CI for β[2, 2]
t critical (95% two-sided)14.8616
Interpretationp-value is undefined for n ≤ 2 — need at least 3 paired points to test the slope.
DirectionPositive slope — y tends to rise as x rises.

Prediction at a new x*

The prediction interval is wider than the confidence band on the fitted line because it accounts for the residual variance of a single new observation, not just the uncertainty in the mean response. Use it when you want a range that should contain a future y-value at x* with the stated probability.

x*
0
ŷ* = α + β·x*
0
95% prediction interval
[0, 0]

Residual diagnostics

ixᵢyᵢŷᵢ = α + β·xᵢeᵢ = yᵢ − ŷᵢstandardised
112200
224400
336600
448800
55101000

Residuals in red have absolute value greater than s (the standard error of estimate) — these are the points that pull on the fit the hardest. A standardised residual beyond ±2 is a typical "check this row" flag.

Show your work

  1. x̄ = (Σ xᵢ) / n = 3, ȳ = (Σ yᵢ) / n = 6.
  2. Σ(xᵢ − x̄)² = 10, Σ(xᵢ − x̄)(yᵢ − ȳ) = 20, Σ(yᵢ − ȳ)² = 40.
  3. β = Σ(xᵢ − x̄)(yᵢ − ȳ) / Σ(xᵢ − x̄)² = 2.
  4. α = ȳ − β·x̄ = 0.
  5. r = Σ(xᵢ − x̄)(yᵢ − ȳ) / √[Σ(xᵢ − x̄)² · Σ(yᵢ − ȳ)²] = 1.0000, and R² = r² = 1.0000.
  6. SSres = Σ(yᵢ − ŷᵢ)² = 0. R² = 1 − SSres/SStot = 1 − 0 / 40 = 1.0000.
  7. s = √(SSres / (n − 2)) = √(0 / 3) = 0.
  8. SE_β = s / √Σ(xᵢ − x̄)² = 0 / √10 = 0.
  9. t = β / SE_β = 2 / 0 = , df = 3, two-sided p = (via the regularised incomplete beta function).
  10. 95% CI for β: β ± tα/2, df · SE_β, where tα/2, 3 = 14.8616, so CI = [2, 2].
  11. At x* = 0: ŷ* = α + β·x* = 0. Half-width of the 95% prediction interval = t · s · √(1 + 1/n + (x* − x̄)² / Σ(xᵢ − x̄)²) = 0. Interval: [0, 0].

Scatter plot, fit & confidence band

1.23.668.410.80.841.9234.085.16xy95% CI band (mean)Regression line ŷ = α + β·xData point (xᵢ, yᵢ)
Fitted line ŷ = α + β·x95% CI band for the mean responseData point

Method. Ordinary least squares (OLS). β = Σ(xᵢ−x̄)(yᵢ−ȳ) / Σ(xᵢ−x̄)², α = ȳ − β·x̄, r = Σ(xᵢ−x̄)(yᵢ−ȳ) / √[Σ(xᵢ−x̄)²·Σ(yᵢ−ȳ)²], R² = r² = 1 − SSres/SStot, SE = √(SSres / (n − 2)), SE_β = SE / √Σ(xᵢ−x̄)², t = β / SE_β (df = n − 2), p-value via the regularised incomplete beta function I[ df / (df + t²) ](df/2, ½), t-critical via bisection on the same CDF.

References. NIST/SEMATECH e-Handbook of Statistical Methods, §6.1 – Simple Linear Regression; Draper & Smith, Applied Regression Analysis (3rd ed., Wiley); Weisberg, Applied Linear Regression (4th ed.); Kutner et al., Applied Linear Statistical Models (5th ed., McGraw-Hill).

Was this helpful?


Linear Regression Calculator

The Linear Regression Calculator is a full ordinary-least-squares (OLS) regression tool that fits a straight line to paired X and Y data and reports the complete diagnostic suite, slope, intercept, Pearson correlation r, coefficient of determination R², standard error of the estimate, standard error of the slope, t-statistic, two-sided p-value, a confidence interval for β at the confidence level you choose, prediction intervals at any new x*, a residuals table with standardised residuals, and a live scatter plot showing the fitted line and its mean-response confidence band. You paste your X and Y lists (comma-, space-, semicolon-, tab-, or newline-separated, a copy/paste from Excel or Google Sheets works without cleanup), pick a confidence level (defaults to 95%), optionally type an x* at which you want a prediction, and the page recomputes everything as you type.

This tool is the comprehensive companion to the simpler "Linear Regression Calculator" entry in the catalogue. It is designed for students learning OLS for the first time, for working scientists who want every diagnostic on one screen, and for data analysts who need prediction intervals (not just confidence intervals) without firing up R or Python. The mathematics is documented inline: the page shows the formula for β, α, R², s, SE_β, the t-statistic, the two-sided p-value, the confidence interval, the prediction interval, and the mean-response band, and it traces through the computation step-by-step for your actual data, so you can see exactly which numbers come from which sums.

How to use this calculator

  1. Type or paste your X values into the X values box on the left. Any plain list works, comma-separated 1, 2, 3, 4, 5, space-separated 1 2 3 4 5, newline-separated (one per line), semicolon-separated, or tab-separated. The parser drops anything that is not a number, so a stray header or footer row from a copy/paste will not break the fit. Excel and Google Sheets paste as tab-separated by default; that works.
  2. Type or paste your Y values into the Y values box on the right, in the same order as the X values. The lists must be the same length. If they are not, the page warns you and uses the first min(|X|, |Y|) pairs so you do not get a silent mismatch.
  3. Set the Confidence level (%). Defaults to 95. The page uses this confidence level for both the slope CI (β ± t · SE_β) and the prediction interval at x*. Valid range is anything strictly between 0 and 100; the calculator falls back to 95% if you type something unparseable.
  4. Optionally type a value into Predict at x.* If you do, the page also displays ŷ* = α + β·x* and a (confidence level)% prediction interval for a single new observation at that x*. Leave it blank to skip the prediction panel.
  5. Click one of the Load example buttons to populate the inputs with a hand-verified test pair. The seven shipped examples are: Perfect line (β = 2, α = 0, R² = 1), Flat line (β = 0, R² undefined), Negative slope (β = −2, α = 12), Anscombe's quartet dataset I (the NIST reference: β ≈ 0.5, R² ≈ 0.67), Sales vs advertising spend (β ≈ 27.4, R² ≈ 0.99), Electricity consumption vs outdoor temperature (β ≈ −44.7, R² ≈ 0.99), and a minimal Two-point fit (β = 2.5, R² = 1, p undefined because n < 3).
  6. Read the Fitted regression line card for the headline result: y = α + β·x, the slope, intercept, Pearson r, R², residual and total sums of squares, standard errors, t-statistic, two-sided p-value, the confidence interval for β, and the t critical value. Below the table, a one-sentence Interpretation tells you whether the slope is statistically significant at α = 0.05 and what the slope means in plain language.
  7. Read the Prediction at a new x card for the fitted value and prediction interval at the x* you typed.
  8. Read the Residual diagnostics table for every observation's xᵢ, yᵢ, fitted ŷᵢ, raw residual eᵢ = yᵢ − ŷᵢ, and standardised residual eᵢ / (s · √(1 − hᵢ)), where hᵢ is the gearing. Residuals whose absolute value exceeds s are highlighted in red, those are the points that pull on the fit the hardest.
  9. Read the Show your work card for the step-by-step derivation: x̄, ȳ, Σ(xᵢ−x̄)², Σ(xᵢ−x̄)(yᵢ−ȳ), Σ(yᵢ−ȳ)², β, α, r, R², SSres, s, SE_β, t, p, the CI, and (if you typed an x*) the prediction-interval half-width.
  10. Read the Scatter plot for the live SVG visualisation. The chart shows the data points, the fitted line ŷ = α + β·x, a shaded 95% (or chosen-level) mean-response confidence band, and, if you typed an x*, a dashed vertical line and a green marker at (x*, ŷ*). You can collapse any of these cards using the toggles on the right of each card header.
  11. Click Copy summary to put a plain-text regression report (n, df, equation, r, R², SE, SE_β, t, p, CI, prediction) on the clipboard for pasting into a lab report or email.

The whole calculation runs in the browser. Inputs are not stored, not transmitted, not associated with any account, and never leave your device.

The formulas

For a dataset of n paired observations (xᵢ, yᵢ), the ordinary least squares (OLS) regression line is the unique line y = α + β·x that minimises the sum of squared residuals Σᵢ (yᵢ − ŷ�)², where ŷᵢ = α + β·xᵢ. The minimisation has a closed-form solution:

Slope. β = Σᵢ (xᵢ − x̄)(yᵢ − ȳ) / Σᵢ (xᵢ − x̄)². The numerator is the sample covariance of x and y (times n), and the denominator is the sample variance of x (times n). β is the average change in y per unit increase in x.

Intercept. α = ȳ − β·x̄. The line passes through the centroid (x̄, ȳ). If x is mean-centred before fitting, α is the predicted y when x = 0, interpret it with care when x = 0 is not a meaningful or in-range value for your application.

Pearson correlation. r = Σᵢ (xᵢ − x̄)(yᵢ − ȳ) / √[Σᵢ (xᵢ − x̄)² · Σᵢ (yᵢ − ȳ)²]. r is symmetric between x and y, lies in [−1, +1], and equals +1 for a perfect positive linear relation, −1 for a perfect negative linear relation, and 0 for no linear relation.

Coefficient of determination. R² = r² = 1 − SSres / SStot, where SSres = Σᵢ (y� − ŷᵢ)² is the residual sum of squares and SStot = Σᵢ (yᵢ − ȳ)² is the total sum of squares. R² is the fraction of variance in y that is "explained" by x in the linear model. R² = 1 means the line passes through every point exactly; R² = 0 means the line is no better than predicting ȳ for every observation.

Standard error of the estimate. s = √(SSres / (n − 2)). The "n − 2" is the residual degrees of freedom, we used two parameters (α and β) to fit n observations, leaving n − 2 independent residual degrees of freedom. s is the typical residual size, in the same units as y.

Standard error of the slope. SE_β = s / √Σᵢ (xᵢ − x̄)². The further x spreads out, the more precisely we can pin down the slope; SE_β shrinks as √Σᵢ (xᵢ − x̄)² grows.

t-statistic and p-value. t = β / SE_β has a Student t-distribution with df = n − 2 degrees of freedom under the null hypothesis that the true slope is zero. The two-sided p-value is

p = I_{df/(df + t²)}(df/2, ½)

where I�(a, b) is the regularised incomplete beta function. This is the standard formula (NIST e-Handbook §6.1, Draper & Smith §2.4); the calculator implements Iₓ via a continued fraction (Lentz's method, Numerical Recipes §6.4) and the Lanczos approximation for log Γ(z), giving agreement with R's pt(t, df, lower.tail = FALSE) * 2 and SciPy's scipy.stats.t.sf(abs(t), df) * 2 to better than 1 part in 10⁶ for df ≥ 2.

Confidence interval for β. β ± t_{α/2, df} · SE_β, where α = 1 − confidence level. The t critical value t_{α/2, df} is the (1 − α/2) quantile of the Student-t distribution. This page computes it by bisection on the same CDF used for the p-value, accurate to ~10⁻⁵ within a few dozen iterations.

Prediction interval at x*. ŷ* ± t_{α/2, df} · s · √(1 + 1/n + (x* − x̄)² / Σᵢ (xᵢ − x̄)²). The "1 +" inside the square root is what distinguishes a prediction interval (for a single new observation) from a confidence interval for the mean response (which uses 1/n without the leading 1). The prediction interval is wider than the mean-response band, especially near the centre of the data.

Mean-response confidence band (plotted). ŷ ± t_{α/2, df} · s · √(1/n + (x − x̄)² / Σᵢ (xᵢ − x̄)²). This is the band you see shaded on the chart. It pinches to its narrowest at x = x̄ and widens as you move away from the centroid.

Standardised residual. rᵢ = eᵢ / (s · √(1 − hᵢ)), where hᵢ = 1/n + (xᵢ − x̄)² / Σᵢ (xᵢ − x̄)² is the gearing of observation i (a measure of how far its x is from the mean). Standardised residuals beyond ±2 (or ±3 in small samples) are typical "check this row" flags.

Worked examples

Example 1, Perfect line. x = [1, 2, 3, 4, 5], y = [2, 4, 6, 8, 10]. x̄ = 3, ȳ = 6, Σ(xᵢ−x̄)² = 10, Σ(xᵢ−x̄)(yᵢ−ȳ) = 20, so β = 20 / 10 = 2.0 and α = 6 − 2·3 = 0.0. The line is y = 0 + 2·x, R² = 1.0, r = 1.0, SSres = 0.0, s = 0.0, SE_β = 0.0, t = ∞, p < 0.0001.

Example 2, Negative slope. x = [1, 2, 3, 4, 5], y = [10, 7, 5, 3, 2]. x̄ = 3, ȳ = 5.4, Σ(xᵢ−x̄)² = 10, Σ(xᵢ−x̄)(yᵢ−ȳ) = (1−3)(10−5.4) + (2−3)(7−5.4) + (3−3)(5−5.4) + (4−3)(3−5.4) + (5−3)(2−5.4) = −9.2 + 2.4 + 0 − 2.4 − 6.8 = −20. β = −20 / 10 = −2.0. α = 5.4 − (−2.0)·3 = 11.4. R² = 1.0 (the points lie exactly on the line y = 11.4 − 2·x). r = −1.0.

Example 3, Two-point fit. x = [0, 10], y = [0, 25]. x̄ = 5, ȳ = 12.5, β = (0−5)(0−12.5) + (10−5)(25−12.5) over (0−5)² + (10−5)² = (−5)(−12.5) + (5)(12.5) over 25 + 25 = 62.5 + 62.5 / 50 = 125 / 50 = 2.5. α = 12.5 − 2.5·5 = 0.0. The line is y = 0 + 2.5·x. R² = 1.0 (the line passes through both points exactly). The standard error of the slope is undefined because df = n − 2 = 0, there are zero residual degrees of freedom. The p-value is therefore undefined, and the CI on β is empty. This is the canonical "you need at least 3 points" warning, and the page reports it gracefully.

Example 4, Anscombe's quartet dataset I (NIST reference). x = [10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5], y = [8.04, 6.95, 7.58, 8.81, 8.33, 9.96, 7.24, 4.26, 10.84, 4.82, 5.68]. This is the canonical reference dataset for linear regression. x̄ = 9.0, ȳ = 7.501 (to 4 dp). β = 0.5 (to several dp), α = 3.0 (to several dp), R² ≈ 0.670 (NIST: 0.670). The page reproduces all three values to four significant figures; the residual diagnostics table lets you verify each (xᵢ, yᵢ) pair by hand.

Example 5, Real sales vs advertising spend. x = [23, 26, 30, 34, 43, 48, 52, 57, 64] (advertising in $thousand), y = [651, 762, 856, 1063, 1190, 1298, 1421, 1600, 1884] (sales in $thousand). x̄ ≈ 41.667, ȳ ≈ 1191.667, β ≈ 27.4 (a $1k increase in advertising is associated with a $27.4k increase in sales), α ≈ 50, R² ≈ 0.99 (the linear fit captures almost all of the variance). p-value is far below 0.0001, the slope is highly statistically significant.

Example 6, Electricity consumption vs outdoor temperature. x = [−2, 3, 8, 12, 18, 22, 27, 31] (°C), y = [1850, 1620, 1380, 1240, 1010, 890, 720, 610] (kWh/day, a winter load profile). x̄ = 14.875, ȳ = 1102.5, β ≈ −44.7, α ≈ 1748, R² ≈ 0.99. The negative slope is the canonical "warmer outside → less heating required" relation. The prediction interval at x* = 0 (a freezing day) is roughly [1800, 1900] kWh/day.

Where it shows up

Econometrics and causal inference. The workhorse of empirical economics. You regress log wages on years of schooling, log GDP on the unemployment rate, log house prices on interest rates, and read the slope as "a one-percent increase in X is associated with a β-percent change in Y, holding everything else in the error term constant". The t-statistic on β is the test of whether the relation is statistically distinguishable from zero. The 95% CI on β is the range of plausible causal magnitudes given this sample.

Biology and pharmacology, dose-response curves. Linear regression on the linear portion of a dose-response curve gives you the slope as "response per unit dose" and the intercept as the baseline response. Below the linear region (very low or very high doses) the relation saturates and you need a non-linear model, but on the linear portion the OLS slope is the headline number. The prediction interval tells you the range of likely responses for a new patient at a given dose.

Finance, capital asset pricing model (CAPM) β. The CAPM β for a stock is the slope of regressing the stock's excess returns on the market's excess returns: rᵢ − r_f = α + β · (r_m − r_f) + ε. A β of 1.2 means the stock moves about 20% more than the market; a β of 0.6 means it moves about 40% less. The intercept α is Jensen's alpha (risk-adjusted excess return). The R² is the fraction of the stock's variance that the market explains.

Machine-learning feature selection. In linear regression and its regularised descendants (Ridge, Lasso, Elastic Net), the per-feature OLS slope and p-value are the classical screening tool. Features whose slopes are statistically indistinguishable from zero (high p-value) are candidates for removal. Modern ML pipelines still report OLS slopes as a baseline against which to compare more complex models.

ANOVA decomposition. The total sum of squares SStot = SSreg + SSres, where SSreg is the regression sum of squares (the variance explained by the fit) and SSres is the residual sum of squares. R² = SSreg / SStot. The F-statistic for the overall regression is F = (SSreg / 1) / (SSres / (n − 2)), and under the null that the slope is zero, F has an F(1, n−2) distribution. Note F = t² for simple linear regression (with one slope), so the t-test on the slope and the F-test on the regression are the same test.

Calibration curves. Analytical instruments (spectrophotometers, chromatographs, qPCR machines) are calibrated by running standards of known concentration, regressing the instrument response on concentration, and using the fitted line to convert an unknown instrument reading into a concentration. The prediction interval at the unknown reading gives you the uncertainty on the reported concentration.

Signal processing and trend estimation. A simple linear trend fit y = α + β·t over a time series gives you the long-run drift rate. The slope's standard error SE_β tells you how tightly the drift is pinned down; the prediction interval at a future t gives the uncertainty on a forward extrapolation. For autocorrelated residuals you need a more sophisticated time-series model (ARIMA, state-space), but for clean data the OLS fit is a useful first look.

Common mistakes

Outlier sensitivity. OLS minimises squared residuals, so a single point with a large residual pulls the line towards itself. If one of your residuals has |e�| > 3s (a "3-sigma outlier" in the standardised-residual sense), check the underlying measurement. Common causes: data-entry typo, instrument mis-calibration for one observation, a regime change (pre/post intervention), or genuine heavy-tailed noise. The standardised residual column in the diagnostics table flags these for you. Mitigations: robust regression (Huber, M-estimators, least-absolute-deviations), or remove the outlier if you can justify it.

Non-linearity. OLS assumes the relation is linear in x. If the underlying relation is curved (quadratic, logarithmic, exponential), the OLS line will be a poor fit and the residuals will show a systematic pattern (positive on one half, negative on the other). Look at the residual plot: if the residuals are all positive on the left and all negative on the right (or vice versa), the relation is curved and you need a polynomial, log, or other conversion. R² can also be misleadingly low for a curved relation, a low R² is not evidence that x and y are unrelated, only that the linear fit is wrong.

Heteroscedasticity (non-constant residual variance). OLS assumes the residuals have the same variance everywhere. If the residuals fan out as x grows (a "megaphone" shape on a residual plot), the standard errors, t-statistics, and confidence intervals are wrong. The slope estimate is still unbiased, but its uncertainty is misstated. Mitigations: weighted least squares (WLS) with weights inversely proportional to the residual variance, reliable (sandwich/Huber-White) standard errors, or a variance-stabilising conversion like log(y).

Autocorrelation. If your observations are ordered in time (or any other sequence) and adjacent residuals are correlated, OLS standard errors are typically too small, the t-statistics look more impressive than they should be, and the CIs are too narrow. The Durbin-Watson statistic is the classical test. Mitigations: Newey-West standard errors, Cochrane-Orcutt / Prais-Winsten conversion, or an ARMA model on the residuals.

Confounding. A significant slope on x → y does not mean x causes y. The classic example: ice-cream sales and drowning deaths both rise in summer (high positive r), but neither causes the other, hot weather is the confounder. In an observational study, you need a control variable, an instrumental variable, or a randomised experiment to support a causal claim. The OLS slope is the right starting point, but it is only a starting point.

Sample size too small. With n = 2, the line passes through both points exactly (R² = 1, s = 0), but the slope has zero residual degrees of freedom and the t-statistic, p-value, and CI are undefined, you cannot infer anything about the population from two points. With n = 3, you have df = 1 and the CI on β is extremely wide; the t critical value at 95% is 12.706 (versus 1.96 for df → ∞). A useful rule of thumb is n ≥ 10 for a rough screen and n ≥ 30 for a publication-quality fit, but the right answer depends on how tight the relation is and how much noise there is.

Predicting far outside the x-range. Extrapolating the OLS line to x-values far beyond the observed range is a recipe for nonsense. The fit is only valid on the convex hull of the observed x; outside that range the linear model may be wildly wrong (and the prediction interval, while formally defined, will be too narrow because it assumes the linear model is correct). Always plot the data, always plot the line, and never trust an extrapolation.

Forgetting to centre x. The intercept α = ȳ − β·x̄ is the predicted y at x = 0. If x = 0 is not meaningful or not in the range of your data, α is hard to interpret and large in magnitude. Reporting "β with α held at 0" (i.e. fitting through the origin) is sometimes defensible, but only when x = 0 is a natural baseline. Otherwise report the slope and the centre of the data, not the intercept.

Frequently Asked Questions

What is the difference between R² and Pearson r? r is the Pearson correlation coefficient, lying in [−1, +1], symmetric in x and y. R² = r² lies in [0, 1] and is the square of r. For simple linear regression (one predictor) they report the same fit: r = ±√R², with the sign of r matching the sign of the slope. R² is the more commonly reported number because it is interpreted as "fraction of variance explained" (it is the ratio SSreg / SStot), but r carries the sign. For multiple regression (more than one predictor) R² is still well-defined but r is not (it has no single sign), so R² is the standard summary.

How many data points do I need? The minimum is 3, you need at least one residual degree of freedom to estimate s, and you need n ≥ 2 just to fit a line. For a useful estimate, aim for n ≥ 10 (rough screen) or n ≥ 30 (publication). The wider your x-range and the smaller the residual variance, the fewer points you need to pin down the slope precisely. The width of the CI on β is roughly proportional to 1/√n and to √(1 / Σ(xᵢ−x̄)²), so spreading x out and adding more points both tighten the CI.

What does the p-value tell me? The two-sided p-value is the probability, under the null hypothesis that the true slope is zero, of observing a |t| at least as large as the one you got. Small p (typically < 0.05) → reject the null → the slope is statistically distinguishable from zero. Large p (typically > 0.05) → fail to reject → the data do not provide strong evidence against β = 0. The p-value is NOT the probability that the true slope is zero, NOR the probability that your result is a false positive, those are common misinterpretations. The p-value is just a tail-area of the t-distribution.

What's the difference between a confidence interval and a prediction interval? A confidence interval for the mean response at x* bounds the average y at x* across hypothetical replications of the experiment. A prediction interval at x* bounds a single new y at x*, it has to absorb both the uncertainty in the line AND the residual variance of a single observation. The prediction interval is always wider, by a factor of roughly √(1 + 1/n + (x*−x̄)²/Σ(xᵢ−x̄)²) / √(1/n + (x*−x̄)²/Σ(xᵢ−x̄)²). Use a confidence interval when you want to know "where is the true line?", and a prediction interval when you want to know "where will the next observation fall?".

My R² is high but my p-value is non-significant. What gives? Possible causes: (a) very small sample size (n ≤ 3 with df = 1, the t critical is huge), (b) the residuals are tiny but the slope is also tiny, R² near 1 can arise with a slope that is non-zero but biologically or practically negligible, (c) the relation is real but tightly clustered in a narrow x-range, so Σ(xᵢ−x̄)² is small and SE_β is correspondingly large. The CI on β is the cleanest summary: if the CI includes 0, the slope is not statistically significant; if it excludes 0, it is.

My R² is low but my p-value is significant. What gives? Possible causes: (a) a large sample size, even a tiny true slope can be statistically significant if n is in the thousands, (b) the relation is real but explains a small fraction of the variance (e.g. height explains ~3% of the variance in income; the slope is significant but R² = 0.03). Statistical significance is about the precision of the slope estimate, not about the practical magnitude of the effect. Report β, its CI, and p-value together; do not rely on R² alone.

Should I drop outliers? Not automatically. Three checks before dropping: (1) is the outlier a data-entry error? If yes, fix it or drop it. (2) is the outlier from a different population than the rest of your data? If yes, fit two separate regressions and report both. (3) is the outlier a real but extreme observation from the same population? If yes, keep it and use robust regression (Huber, M-estimator) to down-weight its influence on the slope. Silent removal of inconvenient points is a form of data manipulation that you should disclose in your methods section.

How does the calculator compute the p-value and t critical? The p-value uses the regularised incomplete beta function Iₓ(a, b) with x = df/(df + t²), a = df/2, b = ½, evaluated via a continued fraction (Lentz's method, Numerical Recipes §6.4). The t critical value uses bisection on the same CDF to find t such that P(T ≤ t) = 1 − α/2, where α = 1 − confidence level. The Lanczos approximation is used for log Γ(z) in the beta function's prefactor. No external libraries are needed; the method agrees with R, SciPy, and Excel to better than 1 part in 10⁶ for df ≥ 2.

Can I paste data from Excel? Yes. Highlight two adjacent columns in Excel or Google Sheets (X in the first, Y in the second), copy (Cmd-C / Ctrl-C), and paste into the X and Y boxes. The parser accepts tab-separated (Excel's default), comma-separated, space-separated, semicolon-separated, and newline-separated. Stray non-numeric tokens (column headers, empty cells) are silently dropped.

Q: Can I use this calculator for professional or commercial purposes? A: Yes. The OLS formulas and the t-distribution computations are exact mathematical identities (modulo numerical-precision conventions in IEEE 754 double-precision arithmetic). The calculator is suitable for academic coursework, business analytics, scientific reporting, financial analysis, engineering calibration, and any other professional or commercial use. As always, check the diagnostic panels (R², p-value, residual plot) before publishing the result, a statistically valid OLS fit is not the same as a causally valid one.

For the Linear Regression Calculator, How often are the Linear Regression Calculator formulas updated? A: The OLS formulas are mathematical identities and have not changed since Gauss and Legendre published them in the early 1800s. The reference texts (NIST e-Handbook §6.1, Draper & Smith 3rd ed., Kutner et al. 5th ed.) restate the same equations. The Student-t distribution was published by William Sealy Gosset in 1908 and has not been revised. There is no proposal to change any of these.

References

  • NIST/SEMATECH, e-Handbook of Statistical Methods, §6.1, Simple Linear Regression, and §7.2, Testing the significance of a regression. https://www.itl.nist.gov/div898/handbook/
  • Draper, N. R. & Smith, H., Applied Regression Analysis (3rd ed., Wiley, 1998). Chapter 1, linear regression in scalar x; chapter 2, inferences in regression analysis.
  • Weisberg, S., Applied Linear Regression (4th ed., Wiley, 2014). Chapter 1, simple linear regression; chapter 2, diagnostics.
  • Kutner, M. H., Nachtsheim, C. J., Neter, J. & Li, W., Applied Linear Statistical Models (5th ed., McGraw-Hill, 2004). Chapter 1, simple linear regression; chapter 2, inferences in regression; chapter 3, diagnostics and remedial measures.
  • Anscombe, F. J. (1973). "Graphs in Statistical Analysis." The American Statistician 27(1): 17 to 21. The source of the four canonical datasets with identical summary statistics but visually distinct structures; dataset I is the linear-regression reference.
  • Press, W. H., Teukolsky, S. A., Vetterling, W. T. & Flannery, B. P., Numerical Recipes: The Art of Scientific Computing (3rd ed., Cambridge University Press, 2007). §6.4, incomplete beta function (Lentz's continued-fraction method); §6.1, Lanczos approximation for log Γ.
  • Abramowitz, M. & Stegun, I. A. (eds.), Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables (Dover, 1965). §26.7, incomplete beta function; §7.1, error function rational approximations.
  • Pearson, K. (1895). "Notes on regression and inheritance in the case of two parents." Philosophical Transactions of the Royal Society of London A 186: 252 to 318. The original publication of r² as the coefficient of regression.
  • Gosset, W. S. [Student] (1908). "The probable error of a mean." Biometrika 6(1): 1 to 25. The first publication of the t-distribution.
  • Gauss, C. F. (1809). Theoria Motus Corporum Coelestium in Sectionibus Conicis Solem Ambientium. The first publication of OLS as a method for fitting the orbit of Ceres.