ForHosting KIT · Developer Utilities

Regression residuals calculator

This regression residuals calculator fits an ordinary least-squares straight line to two equal-length arrays and returns the residual for every observation.

● BetaFree · in your browser
Use it from WebAPIEmailTelegramApp soon

Each residual is calculated as the observed y value minus the value predicted by the fitted line. The result also includes the slope, intercept, and predicted values, making it easy to verify the fit or pass the errors into diagnostics, charts, and later statistical analysis without rebuilding the regression yourself.

What regression residuals reveal

A fitted line summarizes the average linear relationship between an independent variable and an observed response, but the line alone does not show how individual observations depart from that relationship. A residual supplies that missing detail. For each paired observation, the calculator evaluates the fitted value from the least-squares line and subtracts it from the observed y value. A positive residual means the observation lies above the line, while a negative residual means it lies below. A residual of zero means the line predicts that observation exactly. Looking at the full sequence can expose curvature, changing spread, isolated outliers, or runs of errors with the same sign that a slope and intercept cannot communicate. The returned residuals preserve the order of the supplied arrays, so residual number three always corresponds to the third x and third y value. The calculator also returns predicted values in that same order, letting you compare observed, fitted, and error values directly without matching records after the calculation.

How the least-squares fit is calculated

The calculation uses ordinary least squares with an intercept. It first computes the mean of x and the mean of y. The slope is the sum of each centered x value multiplied by its paired centered y value, divided by the sum of squared centered x values. The intercept is then the mean of y minus the slope multiplied by the mean of x. For every input pair, the predicted response equals the intercept plus the slope times x, and the residual equals observed y minus that prediction. This sign convention matters: some contexts display prediction error in the opposite direction, but this capability consistently uses observed minus predicted. At least two finite numeric values are required in each array, and the arrays must be equal in length because regression depends on one-to-one pairs. If every x value is identical, the denominator used for the slope is zero. The capability rejects that case explicitly instead of returning an infinite, missing, or misleading slope and residual series.

Using the output responsibly

Residuals are most useful when you inspect their pattern rather than treating each number in isolation. Plot them against x or against the returned predicted values and look for a roughly unstructured cloud centered near zero. A curve can suggest that a straight line misses a nonlinear relationship. A funnel shape can suggest that error variance changes across the fitted range. A very large positive or negative value can identify an observation worth checking, although it is not automatically a data error. Ordered data may also require an autocorrelation diagnostic because neighboring residuals can depend on one another even when their average is zero. This calculator performs the fit and returns the raw ingredients for those checks; it does not claim that the model assumptions are satisfied or that the relationship is causal. Input order is retained, no rows are removed, and no values are silently coerced. For automated use, the API price is $0.002 per request. Browser execution uses the same deterministic calculation, so repeated runs with identical arrays produce identical results.

Build a residual plot

Pair the returned residuals with x or predicted values to inspect curvature, changing variance, and unusual observations.

Check a regression calculation

Compare the returned slope, intercept, predictions, and observed-minus-predicted errors with results from a spreadsheet or statistics package.

Prepare model diagnostics

Feed the ordered residual array into autocorrelation, error-distribution, or outlier diagnostics without fitting the line again.

How is each residual defined?

Each residual is the observed y value minus the value predicted by the fitted least-squares line.

Why must x and y have equal lengths?

Every x value must pair with exactly one observed y value. Unequal arrays do not define a complete set of regression observations.

What happens when every x value is the same?

The capability returns an invalid input error because x has zero variance and the least-squares slope is undefined.

Does the calculation include an intercept?

Yes. It fits the ordinary least-squares model y equals intercept plus slope times x.

Are the residuals returned in input order?

Yes. Each predicted value and residual keeps the position of its corresponding x and y pair.

What does an API request cost?

The API costs $0.002 per request, while the browser calculator can run the same deterministic logic locally.

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.

POSThttps://api.kit.forhosting.com/stat/regression-residuals

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.

curl -X POST https://api.kit.forhosting.com/stat/regression-residuals \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"x":[1,2,3,4,5],"y":[2,4,5,4,5]}'
{
  "x": [
    1,
    2,
    3,
    4,
    5
  ],
  "y": [
    2,
    4,
    5,
    4,
    5
  ]
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "stat.regression_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.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Read the full KIT documentation →