Linear Regression

Fit a linear regression model to paired X-Y data. Get slope, intercept, R², correlation, adjusted R², RMSE, residuals, and scatter plot with regression line. Free online calculator.

Fit a linear regression model to paired X-Y data

About This Calculator

This linear regression calculator fits a simple linear regression model to your paired X and Y data using the ordinary least-squares (OLS) method. Simply enter your comma-separated X values and Y values, and the calculator instantly computes the slope, intercept, regression equation, R-squared, correlation coefficient, adjusted R-squared, root mean squared error, and residual analysis. It also generates an interactive scatter plot with the fitted regression line and a residual plot to assess model fit.

The linear regression equation is Y = aX + b, where a is the slope and b is the intercept. The slope represents the average change in Y for a one-unit increase in X, while the intercept represents the predicted Y value when X is zero. The least-squares method finds the line that minimizes the sum of squared vertical distances (residuals) between observed data points and the regression line. R-squared (coefficient of determination) measures how well the regression line approximates the real data points, ranging from 0 to 1 with higher values indicating better fit.

Regional Notes

Global: Linear regression is used universally in statistics, data science, economics, engineering, and research. The formulas and interpretation are the same worldwide — no country-specific adjustments are needed. Residual analysis and R-squared interpretation follow standard statistical conventions across all regions.

Frequently Asked Questions

What is linear regression?

Linear regression is a statistical method that models the relationship between an independent variable X and a dependent variable Y by fitting a linear equation Y = aX + b to observed data points. It finds the best-fit straight line that minimizes the sum of squared residuals between observed and predicted values.

How is the linear regression line calculated?

The linear regression line is calculated using the least-squares method. The slope a = Σ((xi − x̄)(yi − ȳ)) / Σ((xi − x̄)²) and the intercept b = ȳ − a × x̄, where x̄ is the mean of X values and ȳ is the mean of Y values. This yields the line that minimizes the sum of squared vertical distances from data points to the line.

What does R-squared mean in linear regression?

R-squared (coefficient of determination) measures the proportion of variance in the dependent variable Y that is explained by the independent variable X in the regression model. It ranges from 0 to 1, where higher values indicate a better fit. For example, an R² of 0.85 means 85% of the variation in Y is explained by X.

How many data points do I need for linear regression?

You need at least 2 data points to fit a line, but for meaningful statistical results we recommend at least 10–30 data points. More data points generally lead to more reliable estimates of the slope and intercept, and better statistical power for hypothesis testing about the relationship between variables.

What is the difference between simple and multiple linear regression?

Simple linear regression models the relationship between one independent variable X and one dependent variable Y using a straight line. Multiple linear regression uses two or more independent variables to predict Y. This calculator handles simple linear regression with one X variable only.

What are residuals in linear regression?

Residuals are the differences between the observed Y values and the predicted Y values from the regression line. A residual = observed Y − predicted Ŷ. Analyzing residuals helps assess model fit — ideally residuals should be randomly scattered around zero with no obvious patterns, indicating a well-specified linear model.

Can I use linear regression for forecasting?

Yes, linear regression can be used for forecasting by plugging new X values into the equation Y = aX + b. However, predictions beyond the range of observed X data (extrapolation) should be made cautiously as the linear relationship may not hold outside the observed range.

What assumptions does linear regression make?

Linear regression makes four key assumptions: linearity (relationship between X and Y is linear), independence (observations are independent of each other), homoscedasticity (residuals have constant variance), and normality (residuals are approximately normally distributed). Violations of these assumptions may affect the validity of the model.