One sometimes encounters a problem when using least squares to find the best fit of a formula to a set of data. A simple example is fitting a line to the Sun's ecliptic longitude as a function of time.
Notice that the nonuniform motion, δ, slopes slightly downward when one would expect just a sinusoidal function. The problem is that least squares warped the error raising it on the left and lowering it on the right to reduce the variance. If one could fit the smaller nonuniform motion first one might avoid the problem but one has to fit the linear portion first to estimate the mean motion, n. What one really wants to do is separate the uniform motion from the nonuniform motion. This can be done by successive residual fits that alternates between finding uniform and nonuniform motion in the residuals. The function correct_α does 10 iterations of this here.
The nonuniform motion is level after the correction and the variance, V, is slightly larger. Here are the programs that were used to do the corrections.
The first function, Δα, fits the nonuniform motion in a set of residuals then uses an new residual to extract some uniform motion from it. The second function, correct_α, repeats this process nitr times.