Isotonic least squares estimator (source code)

= Isotonic least squares estimator
{title2=$\widehat\theta=\arg\min_{\theta_1\leq\cdots\leq\theta_n}\sum_i(y_i-\theta_i)^2$}

For observations $y_1,\ldots,y_n$ in a known covariate order, the isotonic least squares estimator solves
$$
\widehat\theta=\mathop{\arg\min}_{\theta_1\leq\cdots\leq\theta_n}\sum_{i=1}^n(y_i-\theta_i)^2.
$$
It is the <orthogonal projection> of the observation vector onto a closed <convex cone> of nondecreasing sequences. Strict convexity of the squared distance gives a unique estimate.

For data $(3,1,2)$, the first pair violates monotonicity. Pooling it gives mean two, producing $(2,2,2)$ with squared error two. The <pool adjacent violators algorithm> repeatedly merges neighboring blocks whose means are out of order; the fitted value is constant at the block mean on each final block.

Positive observation weights replace squared error by $\sum_iw_i(y_i-\theta_i)^2$ and block means by weighted means. The order restriction regularizes the estimate without specifying a fixed polynomial form. The method requires the ordering to be meaningful; it does not discover an unknown covariate order from the response values.