How this calculation works
Isotonic regression finds fitted values that obey a specified order while staying close to the observations in weighted squared-error loss. It does not assume a polynomial or exponential response curve. This calculator uses the pool-adjacent-violators algorithm: start with one weighted-mean block per observation and merge neighboring blocks whenever their means violate the required direction. Rational arithmetic retains exact block means, fitted values and residual sums within coefficient limits. Both monotonic directions share the same page, and equality between fitted neighbors is allowed.
Minimize Σwᵢ(yᵢ−zᵢ)² subject to z₁≤z₂≤…≤zₙ, or reverse the inequalities for a decreasing fit.A worked example
For ordered observations 3,1,2 with weights 1,3,1 and a nondecreasing requirement, the first two observations violate the order. Their pooled weighted mean is (1×3+3×1)/(1+3)=3/2. The final observation is two, so the fitted sequence is 3/2,3/2,2. The weighted residual cost is 1×(3−3/2)²+3×(1−3/2)²+1×(2−2)²=3. The repeated fitted value is intentional: strict increase is not required.
Good to know
Supports 1–500 ordered rational observations and matching strictly positive rational weights. Input magnitude/precision and exact fraction-growth limits apply. Positions are ordered indices, not an external predictor column; tied predictor coordinates need a stated aggregation policy before entry. The fit is monotone but not strictly monotone. No confidence interval, response-distribution assumption, smoothing penalty, future forecast or interpolation between physical predictor coordinates is inferred. Large common denominators can exceed the exact arithmetic cap and produce an explicit error.
Reference: SciPy — weighted isotonic regression and PAVA (opens in a new tab) ↗
Pooling keeps the original order and changes the fitted responses
Sorting the observed response values would make a monotone sequence immediately, but would also discard the intended ordering of observations. Isotonic regression keeps those positions and adjusts their fitted responses instead. Weights determine how strongly each observation influences a pooled value. A heavily weighted response can pull its block mean toward itself; it is not replaced by an unweighted average just because the final block contains several positions.
After two neighboring blocks merge, their combined mean may violate the order relative to the previous block. The algorithm must check backward and continue pooling until every neighboring block is consistent. Merging only the first visible violation once can therefore produce an incorrect fit. The returned block boundaries and total weights show which observations share a mean, while the full table preserves every original position and its individual weight.
A shape restriction is not evidence that the real relationship is monotone
The calculator enforces the direction entered by the user; it does not test whether that direction is scientifically justified. A monotone fit can absorb random reversals into plateaus, but it can also hide genuine nonmonotonic behavior when the assumption is wrong. The residual sum of squares quantifies the selected objective, not goodness of fit under a probability model or the uncertainty of an estimated response curve.
Scaling every weight by the same positive factor leaves the fitted block means unchanged while multiplying the residual cost by that factor. Zero and negative weights are rejected because this page uses a strictly positive weighted least-squares problem. The Weighted polynomial regression calculator fits a selected polynomial family instead of an order cone; the two methods can return different curves from the same observations without either result being an implementation error. Neither method automatically supplies reliable extrapolation beyond the entered ordered positions.
A few questions, answered
Why does the fitted sequence contain flat blocks?
The constraint is nondecreasing or nonincreasing, so equality is allowed. Pooling violating observations often creates shared weighted-mean plateaus.
Should I sort the input values first?
No. Keep the order of the underlying predictor or sequence. Sorting the response itself would change the problem and can erase every order violation.