Compute the line of best fit using the least squares method. Instantly obtain the slope, intercept, correlation coefficient (r), and coefficient of determination (R²). Visualize your data and the regression line on an interactive chart.
| # | x | y |
|---|
Linear regression is a fundamental statistical method used to model the relationship between a dependent variable (y) and one or more independent variables (x). In its simplest form — simple linear regression — we assume that the relationship can be approximated by a straight line: y = mx + b, where m is the slope and b is the y‑intercept. The goal is to find the line that "best fits" the observed data points.
The most common criterion for "best fit" is the method of least squares, first formalized by Carl Friedrich Gauss and Adrien-Marie Legendre in the early 19th century. This method minimizes the sum of the squared vertical distances (residuals) between each observed data point and the corresponding point on the regression line. The resulting line is called the least‑squares regression line or the line of best fit.
The least‑squares estimates for slope and intercept are:
m = Σ(xᵢ − x̄)(yᵢ − ȳ) / Σ(xᵢ − x̄)² and b = ȳ − m·x̄
where x̄ and ȳ are the sample means of x and y, respectively.
The slope indicates the average change in y for a one‑unit increase in x. A positive slope means y tends to increase as x increases; a negative slope indicates the opposite. The magnitude of the slope reflects the strength of the linear relationship.
The intercept is the predicted value of y when x = 0. In many practical contexts, the intercept may not have a meaningful interpretation if x = 0 is outside the observed range, but it is essential for correctly positioning the regression line.
R² measures the proportion of the variance in y that is explained by the linear model. It ranges from 0 to 1, with higher values indicating a better fit. An R² of 0.80 means that 80% of the variability in y is accounted for by the linear relationship with x.
The correlation coefficient r measures the strength and direction of the linear relationship between x and y. It ranges from −1 to +1. Values near +1 indicate a strong positive correlation, near −1 a strong negative correlation, and near 0 a weak or no linear correlation. Note that R² = r² for simple linear regression.
Predict consumer spending based on income, forecast stock prices using historical trends, or model the relationship between interest rates and housing demand.
Calibrate sensors, analyze experimental data, model the relationship between temperature and pressure, or estimate material properties from test results.
Study the correlation between education level and income, analyze survey data, or explore the relationship between public health interventions and outcomes.
A real estate analyst collects data on 20 recent home sales, recording the size of each house (in square feet) and its sale price. Using linear regression, they find a slope of $150 per square foot and an intercept of $50,000. This model suggests that each additional square foot adds about $150 to the price, and the base price for a 0‑sq‑ft house (hypothetically) is $50,000. With an R² of 0.82, the model explains 82% of the price variability, indicating a strong linear relationship. The analyst can now use this model to estimate the fair market value of new properties based on their size — a practical application of regression in the real estate industry.
The method of least squares was independently discovered by Carl Friedrich Gauss (1809) and Adrien-Marie Legendre (1805). Gauss used it in his work on celestial mechanics to predict the orbit of the dwarf planet Ceres. Legendre published the first explicit description of the method in his work Nouvelles méthodes pour la détermination des orbites des comètes. Their contributions laid the groundwork for modern regression analysis, which was later extended by Sir Francis Galton, Karl Pearson, and Ronald Fisher.
The term "regression" was coined by Galton in the 19th century when he observed that the heights of children of tall parents tended to "regress" toward the population mean. Today, regression analysis is a cornerstone of statistics, machine learning, and data science, underpinning countless predictive models in industry and academia.
For the results of a linear regression to be valid, several key assumptions must be met:
While this calculator does not perform diagnostic tests, we encourage users to examine the scatter plot and consider these assumptions when interpreting results.