What Is Linear Regression?
Linear regression is a statistical method that finds the straight line (y = mx + b) that best fits a set of data points, minimising the sum of squared vertical distances from each point to the line (the ordinary least squares, or OLS, method). It is one of the most widely used techniques in statistics, economics, science, and machine learning.
Given n data points, the slope m and y-intercept b are calculated using the following formulas:
- m (slope) = (n×Σxy − Σx×Σy) / (n×Σx² − (Σx)²)
- b (intercept) = (Σy − m×Σx) / n
- R² = r², where r is the Pearson correlation coefficient
- r = (n×Σxy − Σx×Σy) / √[(n×Σx² − (Σx)²) × (n×Σy² − (Σy)²)]
Interpreting the Results
Understanding what each output means is as important as calculating it correctly.
- Slope (m): the change in y for each one-unit increase in x. A positive slope means y increases as x increases.
- Y-intercept (b): the value of y when x = 0. This may not always be meaningful depending on the context of your data.
- R² (coefficient of determination): ranges from 0 to 1. R² = 0.9 means 90% of the variance in y is explained by x. Values above 0.7 generally indicate a good fit.
- Pearson r: ranges from −1 to +1. Values near ±1 indicate a strong linear relationship; values near 0 indicate a weak or no linear relationship.
Limitations of Simple Linear Regression
Simple linear regression assumes a straight-line relationship between x and y. A high R² does not guarantee the model is correct — always plot your data to check whether a linear model is appropriate. Other important considerations include:
- Outliers can dramatically skew the regression line — review your data for data entry errors.
- Correlation does not imply causation: two variables can be strongly correlated without one causing the other.
- Extrapolation beyond the range of your data is unreliable.
- If the residuals show a pattern, a linear model may not be the best fit — consider a polynomial or other model.
Frequently Asked Questions
What is a good R² value for linear regression?
There is no universal threshold — it depends entirely on the field and application. In physical sciences, R² values above 0.99 are common for controlled experiments. In social sciences and economics, R² values of 0.3–0.6 may be considered acceptable given the inherent complexity of human behaviour. Focus on whether the R² value is appropriate for your specific context.
How many data points do I need?
A minimum of 3 data points is required to calculate a non-trivial regression (2 points always produce a perfect line). In practice, at least 20–30 points are recommended for a statistically meaningful result. The more data points you have, the more reliable the regression equation will be.
Can I use this calculator for multiple regression?
No — this calculator performs simple linear regression with one independent variable (x) and one dependent variable (y). Multiple regression with two or more independent variables requires matrix algebra and is not covered here.