Least squares residuals calculator
This least squares residuals calculator measures how closely a proposed straight line follows observed data.
Run — free
Enter matching x- and y-value lists together with the fitted line's slope and intercept. The result shows every predicted value, every signed residual, the residual sum, the residual sum of squares, and root mean square error. It is useful when you already have a fitted equation and want to inspect its errors, compare candidate lines, verify homework, or identify observations that the line represents poorly.
Enter the observations and fitted line
Provide the observed coordinates as two lists named x_values and y_values. Their positions establish the pairs: the first x-value belongs to the first y-value, the second x-value belongs to the second y-value, and so on. The lists must therefore have equal lengths, contain at least one observation, and contain only finite numbers. Then enter the slope and intercept of the line you want to assess. The calculator uses the equation predicted y = slope × x + intercept; it does not estimate those coefficients for you. This distinction is helpful when a textbook, spreadsheet, statistical package, or earlier regression step has already produced a line and your task is to examine the remaining errors. Keep all values in compatible units. If x is measured in hours and y in dollars, the slope must be dollars per hour and the intercept must be dollars. The output repeats the supplied coefficients and reports the number of paired observations, making it easier to confirm that the intended data and equation were evaluated. Up to 10,000 pairs can be processed in one request.
Read each residual and its sign
For every observation, the calculator first evaluates the fitted line at that x-coordinate. This produces a predicted value. It then computes residual = observed y − predicted y. A positive residual means the observed point lies above the line, while a negative residual means it lies below the line. A residual of zero means the line passes exactly through that observation. The predicted and residual arrays preserve the original input order, so you can compare each returned value with its source point without sorting or matching identifiers. Residual signs matter because they can reveal systematic structure that a single summary number hides. Long runs of positive residuals followed by long runs of negative residuals may indicate curvature, a missing variable, or a changing relationship. Large isolated residuals may identify unusual observations or data-entry mistakes. The residual_sum field adds the signed errors, and mean_residual divides that sum by the number of points. For an ordinary least-squares line with an intercept fitted on the same data, that sum is normally near zero, apart from floating-point rounding. A near-zero sum alone does not prove a good fit because positive and negative errors can cancel.
Use RSS and RMSE to assess fit
The residual sum of squares, often abbreviated RSS or SSE, is the sum of every residual squared. Squaring removes the sign, prevents errors above and below the line from canceling, and gives greater influence to larger misses. An RSS of zero indicates that every supplied point lies exactly on the proposed line. For the same dataset and response units, a smaller RSS indicates a closer fit than a larger RSS. However, RSS grows with the number of observations and its units are the square of the y-unit, so comparisons across datasets of different sizes or different measurement scales need care. The calculator also returns root mean square error, computed as the square root of RSS divided by the observation count. RMSE is expressed in the original y-unit and describes a typical error magnitude, which can be easier to interpret. This value is a descriptive fit measure, not the degrees-of-freedom-adjusted residual standard error used for statistical inference. When comparing candidate lines against exactly the same points, inspect both the aggregate measures and the individual residual pattern. The best numerical score can still conceal curvature, clusters, influential points, or an inappropriate linear model.
What you can do with it
Check a regression assignment
Verify predicted values, signed residuals, and RSS after calculating a fitted line by hand.
Compare candidate lines
Evaluate several proposed slope and intercept pairs against the same observations and compare their RSS values.
Inspect model errors
Locate points with unusually large residuals and look for sign patterns that a summary fit statistic may hide.
FAQ
What is a residual?
A residual is observed y minus the y-value predicted by the fitted line at the same x-coordinate.
Is RSS the same as SSE?
In this context, yes. Residual sum of squares and sum of squared errors both refer to the sum of squared residuals.
Does this calculator find the least-squares line?
No. Supply the slope and intercept of an existing line. This calculator assesses that line by computing its fitted values and residuals.
Can I compare RSS values from different datasets?
Only with caution. RSS depends on the number of observations and the scale of y, so it is most directly comparable for candidate lines evaluated on the same dataset.
How much does the API request cost?
The API price is $0.002 per request. The same deterministic calculation is also available free in the browser.
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/calculus/least-squares-residuals \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"x_values":[0,1,2,3],"y_values":[1,2.2,2.8,4.1],"slope":1,"intercept":1}'const res = await fetch("https://api.kit.forhosting.com/calculus/least-squares-residuals", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"x_values": [
0,
1,
2,
3
],
"y_values": [
1,
2.2,
2.8,
4.1
],
"slope": 1,
"intercept": 1
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/calculus/least-squares-residuals",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"x_values": [
0,
1,
2,
3
],
"y_values": [
1,
2.2,
2.8,
4.1
],
"slope": 1,
"intercept": 1
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/calculus/least-squares-residuals", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"x_values":[0,1,2,3],"y_values":[1,2.2,2.8,4.1],"slope":1,"intercept":1}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"x_values":[0,1,2,3],"y_values":[1,2.2,2.8,4.1],"slope":1,"intercept":1}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/calculus/least-squares-residuals", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"x_values": [
0,
1,
2,
3
],
"y_values": [
1,
2.2,
2.8,
4.1
],
"slope": 1,
"intercept": 1
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "calculus.least_squares_residuals",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Limits
max_items | 10000 |
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |