Enter your x and y values to fit a straight line and predict new values.
Numbers separated by commas, spaces or new lines.
One y for each x, in the same order.
Optional: an x value to predict y for.
Try
Result
You enteredx={1,2,3,4}y={3,5,7,9}
y=2x+1
Slope
2
Intercept
1
r
1
r²
1
Show the work
1
Means of x and y
Each value is measured from the mean of its own variable, so the means come first. There are n=4 pairs.
xˉ=410=2.5yˉ=424=6
2
Sums of squares and products
Sxx measures how spread out the x values are, and Sxy how x and y move together: it is positive when they rise together and negative when one rises as the other falls.
The line of best fit is the line that makes the sum of the squared vertical distances to the points as small as possible. Its slope is the shared movement of x and y divided by the spread of x.
m=SxxSxy=510=2
4
Intercept of the least-squares line
The best-fit line always passes through the point of means, so the intercept follows from putting xˉ and yˉ into y=mx+c.
c=yˉ−mxˉ=6−2×2.5=6−5=1
5
Equation of the line of best fit
Putting m=2 and c=1 into the equation of a line gives y=2x+1.
Using y=mx+c
6
Result
So the line of best fit is y=2x+1.
Scatter plot of the data with the line of best fit.