# Linear Regression & Correlation Calculator

Perform linear regression analysis, solve slope-intercept equations, and compute Pearson correlation coefficient r instantly.

---

- **Canonical URL:** https://dothecalculation.com/calculators/regression-analysis-calculator
- **Category:** Math calculators
- **Publisher:** Do The Calculation (https://dothecalculation.com)
- **Cost:** Free, no account or sign-up required
- **Privacy:** Runs entirely in the browser; inputs are never sent to a server
- **Methodology:** https://dothecalculation.com/methodology

---

## Linear Regression & Correlation Calculator

Perform linear regression analysis, fit bivariate data to y = mx + b, and calculate Pearson r and R-squared.

- Least-squares line fitting
- Pearson correlation coefficient (r)
- Scatter plot & trendline rendering

## Introduction to Linear Regression and Correlation

Linear regression is a statistical method used to model the relationship between a dependent variable \(y\) (the response) and an independent variable \(x\) (the predictor). The goal is to find the best-fitting straight line describing how \(y\) changes as \(x\) increases — the regression line. It's widely used in forecasting, trend analysis, and experimental sciences.

Correlation analysis is closely related but measures the strength and direction of the linear association between two variables rather than a directional predictive line. The standard metric is the Pearson product-moment correlation coefficient \(r\), which ranges from -1 to 1: 1 indicates a perfect positive linear relationship, -1 a perfect negative one, and 0 no linear association.

This calculator performs least-squares linear regression on your coordinates. Enter comma-separated lists of X and Y values, and it calculates the regression slope \(m\), the y-intercept \(b\), Pearson's \(r\), and the coefficient of determination \(R^2\), alongside a scatter plot showing the data points and the fitted trendline.

## How to Use This Calculator

Enter your X values and corresponding Y values as two comma-separated lists of equal length. The calculator fits a least-squares regression line, reports the slope, intercept, Pearson correlation, and R², and plots the data points against the fitted trendline.

## Worked Example: X = 1–5, Y = 2.1, 3.8, 5.2, 7.1, 8.9

$$N=5,\; \sum X=15,\; \sum Y=27.1,\; \sum XY=98.2,\; \sum X^2=55$$

$$m = \frac{5(98.2) - (15)(27.1)}{5(55) - 15^2} = \frac{491 - 406.5}{275-225} = \frac{84.5}{50} = 1.69$$

$$b = \frac{27.1 - 1.69(15)}{5} = 0.35 \implies y = 1.69x + 0.35$$

$$r \approx 0.9988, \qquad R^2 \approx 0.9977$$

With R² near 1, about 99.8% of the variation in Y is explained by this near-perfect linear relationship with X — matching what the calculator returns for its default inputs.

## Related Calculators

To measure the spread of the residuals or either variable on its own, use the [standard deviation calculator](/calculators/standard-deviation-calculator). For a full breakdown of a single dataset's mean, quartiles, and outliers, see the [descriptive statistics calculator](/calculators/descriptive-statistics-calculator). For the two-point version of this same slope, see the [slope calculator](/calculators/slope-calculator), and for how this regression slope shows up as stock beta or a cost-line rate in practice, see [Slope in Business and Economics](/blog/math/slope-in-business-and-economics-guide).

## Least-Squares Fitting Formulas

The equation of the regression line is written as:

$$y = mx + b$$

Where \(m\) is the slope and \(b\) is the y-intercept. The least-squares method finds the values of \(m\) and \(b\) that minimize the sum of squared residuals (the vertical distances between the data points and the line).

The formulas to compute the slope \(m\) and y-intercept \(b\) are:

$$m = \frac{N\sum XY - \sum X \sum Y}{N\sum X^2 - (\sum X)^2}$$

$$b = \frac{\sum Y - m\sum X}{N}$$

Where \(N\) is the number of data pairs, \(\sum X\) is the sum of X values, \(\sum Y\) is the sum of Y values, \(\sum XY\) is the sum of their products, and \(\sum X^2\) is the sum of squared X values.

## Correlation Coefficient (r) and R-Squared (R²)

Pearson's correlation coefficient \(r\) is calculated as:

$$r = \frac{N\sum XY - \sum X \sum Y}{\sqrt{[N\sum X^2 - (\sum X)^2][N\sum Y^2 - (\sum Y)^2]}}$$

The coefficient of determination \(R^2\) is the square of the correlation coefficient. It represents the proportion of the variance in the dependent variable \(y\) that is predictable from the independent variable \(x\). For example, an \(R^2\) of 0.85 means that 85% of the variation in \(y\) is explained by the linear relationship with \(x\), while the remaining 15% is due to random error or other variables.

## Frequently asked questions

### What is linear regression?

Linear regression is a statistical technique that models the relationship between a dependent variable y and an independent variable x using a straight line.

### What is the least-squares method?

It is a mathematical procedure that finds the best-fitting line by minimizing the sum of the squared differences (residuals) between the data points and the line.

### What is the Pearson correlation coefficient (r)?

It is a number between -1 and 1 that measures the strength and direction of the linear relationship between two variables.

### What is R-squared (R²)?

The coefficient of determination R² measures the percentage of variance in the dependent variable that is explained by the regression model.

### How do you interpret a slope (m) of 2.5?

A slope of 2.5 means that for every 1-unit increase in the independent variable x, the dependent variable y is predicted to increase by 2.5 units.

### What is a y-intercept (b)?

The y-intercept is the point where the regression line crosses the y-axis, representing the predicted value of y when x = 0.

### What is a residual in regression?

A residual is the difference between an observed data value and the value predicted by the regression line: y(observed) − y(predicted).

### Does a high correlation imply causation?

No, correlation only indicates that two variables change together. It does not prove that one variable causes the change in the other (correlation does not equal causation).

### What is the range of R-squared?

R-squared ranges from 0 to 1, where 0 means the model explains none of the variance and 1 means it explains all of the variance.

### How do outliers influence regression?

Outliers can heavily skew the regression line because the least-squares method squares the residuals, giving large deviations disproportionate weight.

### What is simple vs. multiple linear regression?

Simple linear regression uses one independent variable to predict y — this is what this calculator computes. Multiple linear regression uses two or more independent variables and isn't supported here.

### What are the assumptions of linear regression?

Key assumptions include linearity (relationship is linear), independence of errors, homoscedasticity (constant variance of residuals), and normality of residuals.

## Related concepts

- **Pearson Correlation Coefficient** — The numeric scale measuring linear association strength.
- **Residuals** — The individual errors between observed data and the fitted model.
- **Least-Squares Fitting** — The mathematical algorithm minimizing squared distances.

## Related guides

- [Slope in Business and Economics: How Rise Over Run Drives Real Decisions](https://dothecalculation.com/blog/math/slope-in-business-and-economics-guide) — Slope isn't just algebra homework — it's the beta behind a stock's risk, the variable cost baked into a spreadsheet trendline, and the pitch of a demand curve. See how rise-over-run shows up in business, economics, and Excel, with worked examples and the Excel SLOPE() function.
- [Standard Deviation Guide: Measure Data Spread Clearly](https://dothecalculation.com/blog/math/standard-deviation-explained) — Understand variance, population vs sample formulas, and data spread with worked examples tied to the live DTC standard deviation calculator.

## Related calculators

- [Binomial Distribution Probability Calculator](https://dothecalculation.com/calculators/binomial-distribution-calculator) — Compute binomial probability mass function, cumulative distribution, mean, and variance instantly with this free statistics calculator.
- [Markov Chain Transition & Steady State Calculator](https://dothecalculation.com/calculators/markov-chain-calculator) — Compute multi-step transition distributions and steady-state probabilities for Markov chains instantly with this free calculator.
- [Normal Distribution & Z-Score Calculator](https://dothecalculation.com/calculators/normal-distribution-calculator) — Compute Z-scores and normal distribution (CDF) probabilities for left-tail, right-tail, and between-bounds ranges with a visual bell curve shown instantly.
- [Percentile & Percentile Rank Calculator](https://dothecalculation.com/calculators/percentile-calculator) — Find the percentile value of a dataset or compute the percentile rank of a specific data point instantly with this free tool.
- [Average Calculator](https://dothecalculation.com/calculators/average-calculator) — Use our free average calculator to find the mean, weighted average, and GPA. Shows step-by-step work for any set of numbers.
- [Chi-Square Test Calculator](https://dothecalculation.com/calculators/chi-square-test-calculator) — Run a Chi-Square goodness-of-fit test on observed vs. expected category counts and get the test statistic, degrees of freedom, and p-value.

---

_This mathematical solver is designed for academic, engineering, and educational analysis. Rounding errors, numerical tolerances, or algorithm constraints might apply near poles, boundary conditions, or complex coordinate spaces. Always verify critical computations independently._

---

_Source: [Do The Calculation](https://dothecalculation.com/calculators/regression-analysis-calculator). Quote freely with attribution and a link to this page._
