Linear Regression Calculator: Line of Best Fit, r, R², Standard Error

Fit a least-squares line to paired data, or run multiple regression on several predictors. Reports the equation, slope, intercept, r, r², the standard error of the estimate, and a scatter plot.

Mode

Paste two columns. One number per row, the same number of rows in each. Values may be comma, space, or newline separated.

Fitted equation

Fit a line

Paste paired data and fit the least-squares line.

Export

ŷ = a + b·x; b = Sxy / Sxx; a = ȳ - b·x̄; S = sqrt(SSE / (n - 2)) How?

How this is calculated

Ordinary least squares chooses the slope b and intercept a that minimize the sum of squared vertical residuals. The slope is the centered covariance Sxy over the x sum of squares Sxx, and the intercept passes the line through the means. The correlation r is Sxy over the square root of Sxx times Syy, and r² is the share of the variance in y that the line accounts for. The standard error of the estimate S is the residual standard deviation, the root of the residual sum of squares SSE over its degrees of freedom, n - 2 in simple mode and n - p - 1 in multiple mode. Multiple regression solves the same least-squares problem on the full design matrix by Householder QR decomposition.

Formula: ŷ = a + b·x; b = Sxy / Sxx; a = ȳ - b·x̄; S = sqrt(SSE / (n - 2))

The method it runs

Both modes fit by ordinary least squares, minimizing the sum of squared vertical residuals. The fit is y-on-x and asymmetric: swapping x and y changes the line even though r is unchanged, because r is symmetric and the regression line is not. Simple mode uses the centered two-pass sums of squares, which stay precise on large-magnitude inputs where the textbook Σxy - ΣxΣy/n shortcut loses digits to cancellation. Multiple mode solves the least-squares problem directly on the design matrix by Householder QR decomposition, the approach R's lm() and LAPACK use, rather than the normal equations, which square the condition number of the design and lose roughly twice as many significant digits on ill-conditioned data.

The convention shown

The "standard error" reported here is the standard error of the estimate, the residual standard deviation, not the standard error of the slope or of the intercept. Its denominator is the residual degrees of freedom: n - 2 in simple mode and n - p - 1 in multiple mode, the unbiased estimator NIST and spreadsheet LINEST use. Every displayed number is rounded to four significant figures; the calculation itself runs in full double precision. When a predictor design is collinear or nearly singular, the tool reports no coefficients rather than inverting a singular matrix and printing an arbitrary solution.

The assumptions it makes

Least squares assumes a linear relationship, independent observations, and a roughly constant spread of the errors. It fits any real data you paste and states these assumptions rather than checking them for you, so read the scatter plot and the residual pattern before trusting the line. Negative and zero values are valid data. This v1 stops at the slope, intercept, r, r², the standard error of the estimate, and the multiple-regression coefficients. For simple regression, the test of whether r (equivalently the slope) differs from zero is the t-test on r with df = n - 2; it lives on the correlation coefficient calculator.

Sources

  1. Linear Least Squares Regression (e-Handbook 4.1.4.1). NIST/SEMATECH. Retrieved .
  2. StRD Linear Least Squares certified datasets (Norris, Longley). NIST. Retrieved .