Linear Regression Calculator

A linear regression calculator fits the best straight line through a set of paired data points so you can describe and predict how one variable changes with another. You enter your x values and your y values as two comma separated lists, and the tool uses the least squares method to find the line y equals slope times x plus intercept that sits closest to all the points. The slope tells you how much y changes for each one unit rise in x, and the intercept is the predicted value of y when x is zero. The calculator also returns r-squared, the proportion of variation in y that the line explains, which is a quick measure of how well the line fits. Least squares works by choosing the slope and intercept that make the total of the squared vertical distances from the points to the line as small as possible, which gives slope as the sum of cross products over the sum of squared x deviations. New Zealand students, scientists, and analysts use regression to model trends such as sales against spend, growth over time, or dose against response, and then to forecast new values. To use it well, enter the same number of x and y values in matching order, plot the data to check the pattern really is roughly straight, and be cautious predicting far outside the range of your data, where the line may not hold. Watch for outliers, since one extreme point can swing the slope, and remember that a good fit shows association rather than proof of cause. Report r-squared with the line so others can judge the fit.

0.6000
Slope
Intercept2.2000
r-squared0.6000
Equationy = 0.6000x + 2.2000

slope = sum((x - xbar)(y - ybar)) / sum((x - xbar)^2). intercept = ybar - slope * xbar. r-squared = r * r.

How it works

The tool finds the mean of the x list and the y list. It sums the products of each pair's deviations from those means to get Sxy, and sums the squared x deviations to get Sxx. The slope is Sxy divided by Sxx, the intercept is the y mean minus the slope times the x mean, and r-squared is the squared correlation.

Worked example

With x values 1,2,3,4,5 and y values 2,4,5,4,5 the means are 3 and 4. Sxy is 6 and Sxx is 10, so the slope is 0.6000. The intercept is 4 minus 0.6 times 3, which is 2.2000, and r-squared is 0.6000.

Related calculators

If you've found a bug, or would like to contact us, or learn more about James Graham and Calculate.co.nz.

Calculate.co.nz is partnered with Interest.co.nz for New Zealand's highest quality calculators and financial analysis.

All calculators and tools are provided for educational and indicative purposes only and do not constitute financial advice.

Calculate.co.nz is proudly part of the Realtor.co.nz group, New Zealand's leading property transaction literacy platform, helping Kiwis understand the home buying and selling process from start to finish. Whether you're a first home buyer navigating your first property purchase, an investor evaluating your next acquisition, or a homeowner planning to sell, Realtor.co.nz provides clear, independent, and trustworthy guidance on every step of the New Zealand property transaction journey.

Calculate.co.nz is also partnered with Health Based Building and Premium Homes to promote informed choices that lead to better long-term outcomes for Kiwi households.

Calculate.co.nz is hosted in Auckland via SiteHost new Zealand.

All content on this website, including calculators, tools, source code, and design, is protected under the Copyright Act 1994 (New Zealand). No part of this site may be reproduced, copied, distributed, stored, or used in any form without prior written permission from the owner.

© 2019 to 2026 Calculate.co.nz. All rights reserved.