TExcelTAD
Home › Electrical & Electronic Measurements › Propagation of Uncertainty, Correlation and Monte Carlo

Propagation of Uncertainty, Correlation and Monte Carlo

The law of propagation in the previous lesson rests on two assumptions that are easy to forget: the inputs are independent, and the model is close to linear over the range of each input's uncertainty. A ratio of two readings from the same meter breaks the first, a magnitude of a noisy small vector breaks the second. This lesson adds the covariance term for the first case and the Monte Carlo method of GUM Supplement 1 (JCGM 101:2008) for the second, and uses Monte Carlo as a check on any budget.

The general law of propagation

For y=f(x1,…,xN)y = f(x_1, \dots, x_N), a first-order Taylor expansion gives

uc2(y)=∑i=1Nci2 u2(xi)+2∑i=1N−1∑j=i+1Nci cj u(xi,xj),u(xi,xj)=rij u(xi) u(xj)u_c^2(y) = \sum_{i=1}^{N} c_i^2\, u^2(x_i) + 2 \sum_{i=1}^{N-1} \sum_{j=i+1}^{N} c_i\, c_j\, u(x_i, x_j), \qquad u(x_i, x_j) = r_{ij}\, u(x_i)\, u(x_j)

where rijr_{ij} is the correlation coefficient between the two estimates. Correlation appears whenever two inputs share an error source: the same meter's gain, the same reference voltage, the same temperature, the same calibration standard.

For a ratio y=x2/x1y = x_2/x_1 the relative form is compact:

(u(y)y)2=(u(x1)x1)2+(u(x2)x2)2−2 r12 u(x1)x1 u(x2)x2\left(\frac{u(y)}{y}\right)^2 = \left(\frac{u(x_1)}{x_1}\right)^2 + \left(\frac{u(x_2)}{x_2}\right)^2 - 2\, r_{12}\, \frac{u(x_1)}{x_1}\, \frac{u(x_2)}{x_2}

With r12=1r_{12} = 1 and equal relative uncertainties the ratio is exact: a shared gain error cancels. That is why ratio measurements (bridges, ratiometric ADCs, divider ratios read with one meter) are so accurate. In a difference y=x1−x2y = x_1 - x_2 of two readings from one meter, a shared offset cancels while a shared gain error survives in proportion to yy; in a sum, a shared offset doubles instead of growing by 2\sqrt{2}. Write the model and let the algebra decide.

Worked example: a divider ratio read with one DMM

Given: V1=10.0000 VV_1 = 10.0000\ \text{V} and V2=3.3330 VV_2 = 3.3330\ \text{V} read on the same range of one DMM whose gain error is within ±50 ppm\pm 50\ \text{ppm} (common to both readings) and whose other errors (noise, linearity) are within ±20 ppm\pm 20\ \text{ppm} independently for each reading; both rectangular.

Find: u(r)/ru(r)/r for r=V2/V1r = V_2/V_1, with and without the correlation.

Solve: each reading has ug=50/3=28.9 ppmu_g = 50/\sqrt{3} = 28.9\ \text{ppm} and un=20/3=11.5 ppmu_n = 20/\sqrt{3} = 11.5\ \text{ppm}, so urel=28.92+11.52=31.1 ppmu_\text{rel} = \sqrt{28.9^2 + 11.5^2} = 31.1\ \text{ppm}, and the correlation coefficient is r12=ug2/urel2=0.86r_{12} = u_g^2/u_\text{rel}^2 = 0.86.

ignoring r12:u(r)r=2×31.1 ppm=44.0 ppmwith r12:u(r)r=2×31.12−2×0.86×31.12 ppm=2 un=16.3 ppm\begin{aligned} \text{ignoring } r_{12}: \quad \frac{u(r)}{r} &= \sqrt{2} \times 31.1\ \text{ppm} = 44.0\ \text{ppm} \\ \text{with } r_{12}: \quad \frac{u(r)}{r} &= \sqrt{2 \times 31.1^2 - 2 \times 0.86 \times 31.1^2}\ \text{ppm} = \sqrt{2}\, u_n = 16.3\ \text{ppm} \end{aligned}

Check: with the correlation only the independent part survives, 2×11.5=16.3 ppm\sqrt{2} \times 11.5 = 16.3\ \text{ppm}, which a Monte Carlo run that draws one shared gain error per trial confirms:

python · try it yourself
import numpy as np

# Divider ratio r = V2 / V1, both read with the same DMM on the same range.
V1, V2 = 10.0000, 3.3330             # volts
g_lim = 50e-6                        # shared gain error limit (relative), rectangular
n_lim = 20e-6                        # independent noise/linearity limit per reading (relative), rectangular
u_g, u_n = g_lim / np.sqrt(3), n_lim / np.sqrt(3)
r = V2 / V1

# Each reading's relative uncertainty is sqrt(u_g^2 + u_n^2); the gain part is fully correlated.
u_rel = np.hypot(u_g, u_n)
uncorr = r * np.sqrt(2) * u_rel                             # pretending the readings are independent
rho = u_g**2 / u_rel**2                                     # correlation coefficient of the two readings
corr = r * np.sqrt(2 * u_rel**2 - 2 * rho * u_rel**2)        # with the covariance term
print(f"r = {r:.5f}; correlation coefficient of the readings = {rho:.2f}")
print(f"u(r) ignoring correlation: {1e6 * uncorr / r:5.1f} ppm")
print(f"u(r) with correlation:     {1e6 * corr / r:5.1f} ppm")

rng = np.random.default_rng(11)
N = 1_000_000
g = rng.uniform(-g_lim, g_lim, N)                            # one gain error shared by both readings
m1 = V1 * (1 + g + rng.uniform(-n_lim, n_lim, N))
m2 = V2 * (1 + g + rng.uniform(-n_lim, n_lim, N))
r_mc = m2 / m1
print(f"Monte Carlo:               {1e6 * r_mc.std() / r:5.1f} ppm")
r = 0.33330; correlation coefficient of the readings = 0.86
u(r) ignoring correlation:  44.0 ppm
u(r) with correlation:      16.3 ppm
Monte Carlo:                16.3 ppm

When first order fails

The law of propagation linearises ff around the estimates. That fails when ff curves strongly within ±u\pm u of an input, or when a sensitivity coefficient is zero at the estimate. A lock-in amplifier measuring a weak signal reports the magnitude A=X2+Y2A = \sqrt{X^2 + Y^2} of two noisy quadrature components. With X=0X = 0, the coefficient ∂A/∂X=X/A\partial A/\partial X = X/A is zero, so first order says the noise on XX does not matter, and it predicts a symmetric interval that reaches almost down to zero. In reality noise on XX can only increase AA: the distribution is skewed (a Rice distribution) and its mean is biased upward.

Monte Carlo propagation (GUM Supplement 1)

  1. Assign a probability distribution to every input (the same ones as in the budget: normal, rectangular, ...), with correlations if any.
  2. Draw MM samples of all inputs, typically M=106M = 10^6.
  3. Evaluate the model for each sample.
  4. Report the mean (or the model value) and the standard deviation of the outputs, and a coverage interval from the percentiles (probabilistically symmetric: 2.5 %2.5\,\% and 97.5 %97.5\,\%) or the shortest interval containing 95 %95\,\%.

No derivatives, no linearity assumption, and correlations are handled by drawing shared errors once per trial. The price is computing time, negligible for any model an engineer writes by hand.

python · try it yourself
import numpy as np

# Magnitude of a small signal from two quadrature components (a lock-in amplifier), microvolts.
X, uX = 0.0, 1.0
Y, uY = 2.0, 1.0
A = np.hypot(X, Y)
# first-order (GUM law of propagation): c_X = X/A = 0, c_Y = Y/A = 1
u_lin = np.hypot(X / A * uX, Y / A * uY)
print(f"first order: A = {A:.3f} uV, u(A) = {u_lin:.3f} uV, 95 % interval [{A - 1.96 * u_lin:.2f}, {A + 1.96 * u_lin:.2f}] uV")

rng = np.random.default_rng(5)
N = 1_000_000
A_mc = np.hypot(rng.normal(X, uX, N), rng.normal(Y, uY, N))
lo, hi = np.percentile(A_mc, [2.5, 97.5])
print(f"Monte Carlo: mean A = {A_mc.mean():.3f} uV, u(A) = {A_mc.std():.3f} uV, "
      f"95 % interval [{lo:.2f}, {hi:.2f}] uV")
# shortest 95 % interval
s = np.sort(A_mc)
k = int(0.95 * N)
i = int(np.argmin(s[k:] - s[:N - k]))
print(f"shortest 95 % interval [{s[i]:.2f}, {s[i + k]:.2f}] uV")

import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(6, 3))
ax.hist(A_mc, bins=200, range=(0, 6), density=True, color="tab:blue", alpha=0.7, label="Monte Carlo")
xs = np.linspace(0, 6, 300)
ax.plot(xs, np.exp(-0.5 * ((xs - A) / u_lin) ** 2) / (u_lin * np.sqrt(2 * np.pi)), "k--", label="first-order normal")
ax.set_xlabel("amplitude A (uV)")
ax.set_ylabel("density")
ax.legend()
fig.tight_layout()
plt.show()
first order: A = 2.000 uV, u(A) = 1.000 uV, 95 % interval [0.04, 3.96] uV
Monte Carlo: mean A = 2.273 uV, u(A) = 0.913 uV, 95 % interval [0.59, 4.13] uV
shortest 95 % interval [0.49, 4.01] uV

The Monte Carlo interval is shifted and asymmetric: the true signal is very unlikely to be below 0.5 μV0.5\ \mu\text{V}, and the mean output (2.27 μV2.27\ \mu\text{V}) is biased above the estimate (2.00 μV2.00\ \mu\text{V}). The first-order interval is wrong at both ends. In practice, signal magnitudes near the noise floor (lock-in, spectrum analysers, RMS of noise) all behave like this (Spectrum Analysers).

Guided lab: check a budget by Monte Carlo

Hand calculation. Take the budget of the shunt example: uc(I)=147 ppmu_c(I) = 147\ \text{ppm} of 1.5229 A1.5229\ \text{A} from first-order propagation.

Simulation. Write a Monte Carlo version: draw VV (normal for the Type A part, rectangular for the spec), RR (normal, σ=10 μΩ\sigma = 10\ \mu\Omega), α\alpha (rectangular ±10 ppm/K\pm 10\ \text{ppm/K}) and TT (rectangular ±1 K\pm 1\ \text{K}), evaluate the model and compare the standard deviation with 147 ppm147\ \text{ppm}. The model is nearly linear, so expect agreement within a few ppm; a disagreement means a mistake in a sensitivity coefficient.

What you would measure. For the divider ratio: measure V1V_1 and V2V_2 of a 10 V10\ \text{V} divider with one 6½-digit DMM, then with two different DMMs. The one-meter ratio should repeat to a few ppm across days; the two-meter ratio drifts by the meters' relative gain errors (tens of ppm). This is the experimental face of the correlation term.

Hazards and safe setup. Low-voltage divider from a current-limited supply; nothing else.

Pitfalls

  • Ignoring correlation in a ratio (overestimates) or in a sum of readings from one meter (underestimates).
  • Using first-order propagation near a zero sensitivity coefficient or near a physical bound (a magnitude, a resistance near zero).
  • Running Monte Carlo with too few trials: the 2.5 %2.5\,\% percentile needs about 10510^5 trials or more to be stable to two digits.
  • Forgetting to fix the random seed in a report: results should be reproducible.

Practice

  1. Two readings with urel=30 ppmu_\text{rel} = 30\ \text{ppm} each and r12=1r_{12} = 1: what is u(r)/ru(r)/r for their ratio, and for their product?
  2. Why is a Wheatstone bridge insensitive to the exact value of its supply voltage?
Answer
  1. Ratio: 302+302−2×30×30=0\sqrt{30^2 + 30^2 - 2 \times 30 \times 30} = 0. Product: 302+302+2×30×30=60 ppm\sqrt{30^2 + 30^2 + 2 \times 30 \times 30} = 60\ \text{ppm} (fully correlated terms add linearly).
  2. At balance the condition is a ratio of resistances; the supply multiplies both arms equally, a perfectly correlated factor that cancels (DC Bridges).

Test yourself

Two readings share the same gain error. In their ratio this error

  1. doubles
  2. adds in quadrature
  3. cancels
  4. becomes random

First-order propagation is unreliable when

  1. the model is a product of powers
  2. a sensitivity coefficient is zero at the estimate or the model curves strongly within the uncertainty
  3. the inputs are normal
  4. there are more than three inputs

GUM Supplement 1 gives a coverage interval from

  1. y±2ucy \pm 2u_c always
  2. percentiles of the simulated output distribution
  3. the largest input uncertainty
  4. the Welch-Satterthwaite formula

The mean of X2+Y2\sqrt{X^2 + Y^2} with noisy XX and YY is

  1. exactly the noise-free magnitude
  2. biased upward
  3. biased downward
  4. zero