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.
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
- Pearson Correlation Calculator: correlation of two lists.
- One-Way ANOVA Calculator: compare group means.
- Confidence Interval Calculator: interval for a mean.