# Linear Regression Calculator

Fit a simple least-squares linear regression model and calculate slope, intercept, R squared, and predictions

> Canonical page: https://elysiatools.com/en/tools/linear-regression-calculator

- **Category:** Math & Numbers

- **Keywords:** linear regression, least squares, slope, intercept, r squared, calculator

## Overview

The Linear Regression Calculator is a specialized tool designed to fit a simple least-squares regression model to your data. It provides essential statistical metrics, including the slope, y-intercept, and R-squared value, while allowing you to generate precise predictions for specific X values based on the calculated trend line.

## Inputs

- **Data Pairs** (textarea): One pair per line, e.g. 1, 2 2, 4 3, 5
- **X Values (Optional)** (text): Alternative input: 1, 2, 3, 4
- **Y Values (Optional)** (text): Alternative input: 2, 3, 5, 7
- **Prediction X (Optional)** (text): e.g. 6
- **Decimal Places** (number)

## When to use

- When you need to determine the mathematical relationship between two continuous variables.
- When evaluating the strength of a linear correlation using the R-squared coefficient.
- When predicting future outcomes or missing values based on historical data trends.

## How it works

- Input your data as coordinate pairs (X, Y) or as separate lists of X and Y values.
- Specify an optional X value if you wish to calculate a specific Y prediction based on the fitted model.
- Set the desired number of decimal places for the output results to ensure numerical precision.
- The tool applies the least-squares method to minimize the sum of squared residuals and returns the model parameters in JSON format.

## Use cases

- Analyzing the correlation between advertising spend and monthly sales revenue.
- Estimating crop yields based on varying levels of rainfall or fertilizer application.
- Predicting student test scores based on the number of hours spent studying.

## Frequently asked questions

### What is the R-squared value?

It is the coefficient of determination that measures how well the linear regression model fits the data, with 1.0 representing a perfect fit.

### Can I input data in different formats?

Yes, you can provide data as line-separated pairs or as two distinct lists of X and Y values.

### What does the slope represent?

The slope indicates the average change in the Y variable for every one-unit increase in the X variable.

### Is there a limit to the number of data points?

The tool handles standard datasets efficiently; you must provide at least two pairs to calculate a valid regression line.

### What is the intercept?

The intercept is the predicted value of Y when the X value is zero, representing where the line crosses the Y-axis.

## Related tools

- [Bayes Theorem Calculator](https://elysiatools.com/en/tools/bayes-theorem-calculator): Calculate posterior probability P(A given B) using prior, likelihood, and false-positive rate
- [Bearing Capacity Calculator (Terzaghi)](https://elysiatools.com/en/tools/bearing-capacity-calculator): Calculate the Terzaghi ultimate bearing capacity of a shallow foundation: q_ult = c·Nc·sc + q·Nq·sq + 0.5·γ·B·Nγ·sγ. Computes Nc/Nq/Nγ and shape factors automatically; supports strip, square, and circular footings. Result in kPa.
- [Belt Pulley Speed Ratio Calculator](https://elysiatools.com/en/tools/belt-pulley-speed-ratio): Calculate the ratio, driven speed and belt linear speed of a belt drive. i = d₂/d₁ = n₁/n₂, belt speed v = π·d·n/60. Supports mm/cm/m/inch diameter units.
- [Bending Stress Calculator](https://elysiatools.com/en/tools/bending-stress-calculator): Calculate the maximum bending (flexural) stress σ_max = M·c/I = M/Z at the outermost fiber of a beam section. Supports solid circle, rectangle, hollow tube, and I-beam; computes I, section modulus Z, and distance c automatically. Stress in MPa.
- [Break-Even Calculator](https://elysiatools.com/en/tools/break-even-calculator): Calculate the break-even point for a product or business based on fixed costs, variable costs, and price
- [Cantilever Beam Calculator](https://elysiatools.com/en/tools/cantilever-beam-calculator): Calculate the maximum bending moment M_max, maximum shear force V_max and free-end deflection δ_max of a cantilever beam under a free-end point load P or a uniformly distributed load q. Point load: δ = PL³/(3EI); UDL: δ = qL⁴/(8EI).
- [Determinant Calculator](https://elysiatools.com/en/tools/determinant-calculator): Compute the determinant of a square matrix and explain the main calculation steps
- [Factorial Calculator](https://elysiatools.com/en/tools/factorial-calculator): Calculate n! for a non-negative integer with exact BigInt output, optional steps, and related values such as trailing zeros

## Samples

- [Android Image Processing Java Samples](https://elysiatools.com/en/samples/android-image-processing-java): Android Java image processing examples including reading/saving images, scaling, and format conversion
- [Android Image Processing Kotlin Samples](https://elysiatools.com/en/samples/android-image-processing-kotlin): Android Kotlin image processing examples including reading/saving images, scaling, and format conversion
- [Web Image Processing Python Samples](https://elysiatools.com/en/samples/web-image-processing-python): Web Python image processing examples using PIL/Pillow including reading, saving, resizing, and format conversion
- [Web Image Processing Rust Samples](https://elysiatools.com/en/samples/web-image-processing-rust): Web Rust image processing examples including image read/save, scaling, and format conversion
