Linear Regression CalculatorFree online math calculator — instant results, no sign-up
Fit a least-squares line and calculate its coefficient of determination.
About the Linear Regression Calculator
The Linear Regression Calculator fits a least-squares line to paired observations and reports its slope, intercept, and coefficient of determination (R squared). It treats Values as the x-coordinates and Paired values or weights as the corresponding y-coordinates. With the default inputs, the fitted line is y = 0.5x, with an intercept of 0 and R squared of 1.
- Values
- Enter the independent-variable values x in observation order, using a consistent unit for all entries; the default is 2, 4, 6, 8, 10.
- Paired values or weights
- For this regression calculation, enter the dependent-variable values y paired in order with x, not weights, using a consistent unit for all entries; the default is 1, 2, 3, 4, 5.
Formula and method
For sums over i = 1 to n: x̄ = (Σx_i)/n; ȳ = (Σy_i)/n; b = Σ[(x_i − x̄)(y_i − ȳ)] / Σ(x_i − x̄)²; a = ȳ − bx̄; ŷ_i = a + bx_i; R² = 1 − Σ(y_i − ŷ_i)² / Σ(y_i − ȳ)². For the default inputs, x̄ = 6 and ȳ = 3, so b = 20/40 = 0.5, a = 3 − 0.5 × 6 = 0, and R² = 1 − 0/10 = 1.
- nNumber of paired observations.
- iObservation index, running from 1 through n.
- x_iThe ith entry in Values, used as the independent variable.
- y_iThe ith entry in Paired values or weights, used as the dependent variable.
- x̄, ȳArithmetic means of the x-values and y-values, respectively.
- ΣSummation over all paired observations.
- bFitted slope, measured in y-units per x-unit.
- aFitted intercept, measured in y-units.
- ŷ_iPredicted y-value at x_i on the fitted line.
- R²Dimensionless coefficient of determination, comparing squared residuals with total variation in y.
Pair entries by position and calculate the means of both lists. Divide the sum of cross-products of deviations from the means by the sum of squared x-deviations to obtain the slope, then calculate the intercept from the means. This selects the line that minimizes the sum of squared vertical residuals. Predict y for each supplied x and compare the residual sum of squares with the total sum of squares to obtain R squared.
Worked example
These are the calculator's starting values and the results it actually produces for them.
Inputs
- Values2, 4, 6, 8, 10
- Paired values or weights1, 2, 3, 4, 5
Results
- Slope0.5
- Intercept0
- R squared1
How to use the Linear Regression Calculator
- 1Enter 2, 4, 6, 8, 10 in Values for the default example, or replace them with your x-observations.
- 2Enter 1, 2, 3, 4, 5 in Paired values or weights for the default example, or enter your corresponding y-observations.
- 3Check that the lists contain the same number of numeric entries and that each x-value is aligned with its intended y-value.
- 4Run the calculation to fit the least-squares line.
- 5Read the slope, intercept, and R squared rows; the default inputs give 0.5, 0, and 1, respectively.
Reading your result
Slope reports the predicted change in y for a one-unit increase in x; the default slope of 0.5 means y increases by 0.5 y-units per x-unit. Intercept reports the predicted y-value at x = 0; the default intercept is 0, although x = 0 lies outside the supplied range. R squared reports the fraction of observed variation in y accounted for by the fitted line relative to predicting the mean y; the default R squared of 1 means every supplied pair lies exactly on the line.
Limitations
The lists must have equal lengths, contain valid numeric observations, and include at least two pairs with distinct x-values. If all x-values are equal, the slope is undefined; if all y-values are equal, the stated R squared formula is undefined. This is unweighted ordinary least squares, despite the second input's shared label mentioning weights. Outliers can strongly affect the fit, and a straight line may poorly represent curved patterns. A high R squared does not establish causation or guarantee accurate predictions outside the observed x-range. The reported fit alone does not provide confidence intervals or validate assumptions needed for statistical inference.
Common questions
Does Paired values or weights accept regression weights here?+
In this calculation, its entries are paired y-values, not regression weights. The default input pairs are (2, 1), (4, 2), (6, 3), (8, 4), and (10, 5).
Why do the default inputs produce a slope of 0.5 and R squared of 1?+
Every default y-value equals half its paired x-value. The line y = 0.5x therefore passes through all five observations, giving an intercept of 0 and no residual error.
Does swapping the two lists leave the fitted line unchanged?+
No. Regression minimizes vertical errors in whichever list is treated as y. Swapping the default lists gives y = 2x rather than y = 0.5x; both have R squared of 1 because the default relationship is exact.
Can I fit a line if every entry in Values is identical?+
No unique slope can be calculated because the sum of squared x-deviations is zero. Include at least two distinct x-values to fit the line.
Does the calculator save my information?+
Calculations run in your browser. While signed in, inputs and results are automatically recorded in account history; saving a result creates a separate saved record.
Further reading
You might also like
Standard Deviation Calculator
Sample and population standard deviation of a data set.
Number Sequence Calculator
Terms and sums of arithmetic and geometric sequences.
Sample Size Calculator
Sample size for a survey at a confidence level.
Probability Calculator
Combined probabilities of two independent events.
Statistics Calculator
Summary statistics for a data set.
Mean, Median, Mode, Range Calculator
Central tendency and spread of a list.
Results are estimates for informational purposes and are not financial, medical or legal advice.