Fundamentals / Numerical mathematics / Inverse problems and least squares

Calibrating two instruments when both axes fluctuate

The horizontal axis of a calibration plot is often described as an input. In this experiment it is itself a reading from a second noisy instrument. Infer a straight calibration relation from paired data, derive the metric in which the fit should be performed, and use a change of units to reveal an easily overlooked modelling error.

What was actually held fixed during the experiment?

At setting \(i\), let the unknown true first-channel signal be \(\xi_i\), measured in millivolts. Suppose the true second-channel value, in kelvin, is \(a+b\xi_i\) over the limited operating range. What the laboratory records is the pair \(x_i=\xi_i+\epsilon_{xi}\),

\[y_i=a+b\xi_i+\epsilon_{yi}.\]

Repeatability tests supply standard deviations \(s_x,s_y>0\). For now fix them across observations, with independent zero-mean Gaussian errors in both channels. The physical settings \(\xi_i\) are treated as unknown fixed quantities, one per record.

Ordinary vertical least squares implicitly treats the observed \(x_i\) as the exact horizontal values. That choice would make sense if the settings had been specified by a sufficiently accurate standard and \(x_i\) denoted those settings. It changes the inference when \(x_i\) comes from a noisy meter. Every displayed point can then move both horizontally and vertically as we estimate its underlying position on the calibration line.

A geometric phrase like “shortest distance to the line” has no unique experimental meaning yet. A displacement of one millivolt and a displacement of one kelvin cannot be compared by drawing the points on square graph paper. Measurement uncertainty supplies a metric. Divide each horizontal adjustment by \(s_x\) and each vertical one by \(s_y\). Under the stated Gaussian assumptions their squared sum is proportional to twice the negative log likelihood, up to additive constants independent of the parameters. This also clarifies why the relative scale requires a separate calibration: one cloud does not automatically reveal how much of its spread belongs to each axis.

Eliminate the unobserved setting algebraically

For a proposed line, estimate each unknown \(\xi_i\) by minimising its pair of squared corrections. Define \(r_i=y_i-a-bx_i\) and write \(\xi_i=x_i+\delta_i\). Then the horizontal term is \(\delta_i^2/s_x^2\), and the vertical term is \((r_i-b\delta_i)^2/s_y^2\). Differentiating their sum with respect to \(\delta_i\) leaves a scalar linear equation. Its solution apportions the original vertical residual between the two measurement errors.

\[\delta_i=\frac{b s_x^2 r_i}{s_y^2+b^2s_x^2},\]
\[y_i-a-b\xi_i=\frac{s_y^2r_i}{s_y^2+b^2s_x^2}.\]

For example, let \(b=2\,\mathrm{K/mV}\), \(s_x=0.5\,\mathrm{mV}\), \(s_y=1\,\mathrm K\), and \(r_i=1\,\mathrm K\). The inferred horizontal correction is 0.25 mV and the remaining vertical error is 0.5 K. In uncertainty units each has magnitude one half and the squared cost is one half. Keeping the first reading fixed would assign the whole kelvin to the second channel and produce cost one. The formula decides the split from the line sensitivity and the two instrument uncertainties.

Substitute the optimal correction into the objective. The profiled contribution simplifies to \(r_i^2/(s_y^2+b^2s_x^2)\). For fixed slope the denominator is common to all records. Differentiating with respect to \(a\) therefore gives

\[a=\bar y-b\bar x.\]

Every candidate slope now passes through the sample centroid. The remaining scalar optimisation is an independent way to check a geometric solution.

\[J(b)=\frac{\sum_i[(y_i-\bar y)-b(x_i-\bar x)]^2}{s_y^2+b^2s_x^2}.\]

Do not attach a slope-dependent logarithm of this denominator to the present objective. We obtained it by maximising over fixed nuisance coordinates, each with its own original pair of measurement densities and fixed noise normalisation. A different experiment might specify a distribution for the latent settings and integrate them out instead. That would be a different likelihood construction. The fitting rule follows from how the unknowns and observations have been modelled.

Fit in coordinates in which the noise is isotropic

Make a data matrix with one row per observation. Subtract the centroid and divide the first column by \(s_x\), the second by \(s_y\). Call the result \(Z\). A line through the origin in these whitened coordinates is completely specified by a unit normal \(n\), including vertical lines that would cause a slope parameter to diverge. The squared perpendicular distances sum to \(\|Zn\|^2=n^TZ^TZn\). Minimising over unit normals selects the eigenvector of the smallest eigenvalue of \(Z^TZ\). With a singular value decomposition \(Z=U\Sigma V^T\), it is the last right singular vector.

The other right singular vector points along the fitted line. Transform that direction back to the physical instrument units by multiplying its components by \(s_x\) and \(s_y\). The slope is the ratio of those transformed components. The sign of the singular vector is mathematically arbitrary and has no effect on the line. The feet of the perpendiculars are simple in whitened coordinates: subtract \((z_i\cdot n)n\) from each whitened point. Transform them back and add the centroid. In a physical plot with unlike axis scales those connecting segments need not look perpendicular by eye.

A three-point calibration you can check without a computer

Use dimensionless readings \((-1,-2),(0,1),(1,1)\) and equal measurement standard deviations. Both column means are zero. The centred sums are

\[S_{xx}=2,S_{yy}=6,S_{xy}=3.\]

Ordinary vertical least squares gives slope \(3/2\). For a line direction \((1,b)\), requiring that this direction be an eigenvector of the scatter matrix yields

\[3+6b=b(2+3b).\]

There are two roots. The direction along the major axis corresponds to the positive one,

\[b=(4+\sqrt{52})/6\simeq1.8685.\]

The negative root is the perpendicular minor-axis direction.

The residual cost of the vertical fit, evaluated in its own vertical metric, should not be directly compared with the perpendicular cost of the other fit. Evaluate both using the same profiled cost instead. With \(s_x=s_y=1\), the minimum equals the smaller scatter eigenvalue \((8-\sqrt{52})/2\simeq0.39445\). Substituting 1.5 into the profiled formula yields \((6-9+4.5)/(1+2.25)\simeq0.46154\). The orthogonal fit has achieved the smaller value in the metric actually specified by the instrument model.

Observations and fitted lines from two calibration assumptions, next to the profiled squared correction as a function of slope.Open full-size diagram
The marked minimum comes from the small singular vector of the whitened observations. The curve calculates the same score by independently eliminating the unknown horizontal reading associated with each data point.

When is a best direction too weak to interpret?

The separating quantity is the gap between the two eigenvalues of the whitened scatter matrix. If they are nearly equal, the data cloud is nearly round in the metric that matters. Rotating the line then changes the score very little. If they are exactly equal, every line through the centre has the same score. A numerical routine can return a perfectly normalised eigenvector in this situation. Its normalisation and tiny algebraic residual say nothing about whether the data determine a preferred direction.

Try the notebook's seven paired readings first with its default uncertainty scales. The weighted slope is approximately 1.7290 K/mV and the vertical slope about 1.6490 K/mV. Decrease the declared uncertainty of the first channel while retaining the numerical observations. The fit approaches the vertical least-squares answer because horizontal adjustments become expensive. Increasing this uncertainty instead assigns more of a discrepancy to the first instrument. When the recorded inputs span too narrow a range, even very accurate readouts cannot robustly establish a sensitivity over a wide operating range.

A reliable implementation should survive changes of units. Convert millivolts to volts, and divide both the first coordinates and their standard deviation by one thousand. The whitened first column and the minimum score remain unchanged. The newly reported slope has units of kelvin per volt and is one thousand times the original physical number. If the slope fails this conversion test, inspect noise scaling, plotting aspect ratios and any normalisation by sample variance that was used in place of a known measurement uncertainty.

One may also ask for a confidence interval on the inferred line. That requires a sampling model for repeat experiments. In particular, treating each corrected pair as a known physical truth ignores uncertainty in the inferred settings. A simple exploratory test simulates new independent measurement errors at plausible fitted settings, refits the complete procedure and examines the spread of slopes over many trials. The result is conditional on those settings and the stated noise levels. A common calibration error shared by every specimen or correlated errors within a reading would require a different covariance model before interpreting such an interval.

A useful practical control is to interchange the two instruments, fit again with interchanged uncertainties, and convert the line to the original orientation. Whitened orthogonal regression should recover the same geometry. In contrast, two separate vertical regressions generally give different lines after their slopes are inverted. Directional regression can be an appropriate predictor for new observations under another sampling model; this reversal test specifically examines the symmetry of the latent-line calibration adopted here.

Tutorial on calibration uncertainty and identifiability

1. With slope 2 and a positive vertical residual of 1 in the units of the hand example, change \(s_x\) to 0.25 and retain \(s_y=1\). What correction is assigned to each instrument?

Work through the solution

The denominator becomes

\[1+4(0.25)^2=1.25.\]

The latent first coordinate increases by \(2(0.25)^2/1.25=0.1\). The unexplained vertical error is

\[1/1.25=0.8.\]

Scaled corrections of 0.4 and 0.8 give a total cost of 0.80. Improving the horizontal meter shifts more of the inferred error to the vertical channel.

2. Multiply both standard deviations by three while retaining the same actual data. Which reported quantities change?

Work through the solution

The centred whitened matrix is divided by three. Both singular values scale by one third, but the right singular directions and fitted physical line stay fixed. The squared score decreases by a factor of nine. A fixed fit can therefore be more or less consistent with an instrument specification even when its slope is unchanged.

3. Four measurements in whitened coordinates lie at \((1,0),(-1,0),(0,1),(0,-1)\). What slope will a physically meaningful calibration report?

Work through the solution

The scatter matrix is twice the identity, so every line through the origin has squared score two. A unique calibration slope cannot be recovered from these measurements under the stated equal-uncertainty model. To break the symmetry, obtain additional measurements spanning a wider range of true settings or supply new information about instrument uncertainties.

Further reading · NIST, orthogonal distance regression and errors in the explanatory variables

Change parameters · Calibrating two instruments when both axes fluctuate

Change one input at a time and compare the recalculated curves with the argument above. The browser evaluates this small model locally; the accompanying numerical values state its assumptions and reference checks. Reset restores the reference inputs, and the data can be downloaded as CSV.