A robot repeatability report can calculate two different variances from the same readings. One describes the observed run. The other estimates the variance of a process under sampling assumptions. NumPy expresses the choice with its ddof parameter. If a report saves only the result and the units, a later reader may be unable to reproduce it or tell which quantity it represents.
This example uses invented displacement readings and was checked with NumPy 2.5.2. It illustrates the calculation and handling of missing readings. It does not estimate the repeatability of a particular machine or establish a testing standard.
Calculate both summaries from the same observations
Take readings of 2, 4, and 6 micrometers. Their mean is 4 micrometers. The squared deviations from that mean are 4, 0, and 4 square micrometers, and their sum is 8. Dividing by the count of three gives 8/3 square micrometers. Dividing by the count minus one gives 4 square micrometers.
import numpy as np
from statistics import pvariance, variance
readings = np.array([2., 4., 6.])
observed = np.var(readings, ddof=0)
estimated = np.var(readings, ddof=1)
assert observed == pvariance(readings.tolist()) == 8 / 3
assert estimated == variance(readings.tolist()) == 4.
When a report describes all three observations as a complete run, the mean squared deviation from their own mean uses the first denominator. When the readings are treated as independent, identically distributed samples from a process with finite variance and an unknown mean, dividing by the count minus one gives an unbiased estimator of that process variance. The sample mean is calculated using the same readings whose deviations enter the estimate.
A larger estimate with the second convention does not indicate a change in the machine. The readings and their squared deviations are unchanged. For a nonconstant set of three values, the two results differ by a factor of 3/2. The factor approaches one as the count increases. The distinction can be especially visible when a short run is compared with a report generated by a different tool.
Count the readings that entered each result
A data set may be rectangular because every channel is sampled on a common schedule, yet contain different numbers of observations after dropouts. In the example below, missing readings are encoded as NaN. NumPy's nanvar counts the non-NaN values in each reduced slice for its denominator. With ddof=1, a channel needs at least two observations for a finite sample variance when the input measurements themselves are finite.
measurements = np.array([
[2., 4., 6.],
[1., np.nan, 3.],
[np.nan, 8., np.nan],
[np.nan, np.nan, np.nan],
])
counts = np.count_nonzero(~np.isnan(measurements), axis=1)
estimates = np.full(len(measurements), np.nan)
eligible = counts > 1
estimates[eligible] = np.nanvar(
measurements[eligible], axis=1, ddof=1
)
assert counts.tolist() == [3, 2, 1, 0]
assert estimates[:2].tolist() == [4., 2.]
assert np.isnan(estimates[2:]).all()
Rows represent channels and columns represent time positions. The first two channels use denominators of two and one. The last two are retained in the report with an unavailable result. NumPy would also return NaN for those slices with the requested degrees of freedom and emit a warning. Checking the counts first makes the data gap explicit. If infinities or a device-specific sentinel can appear, handle those under the input contract before using the NaN-only rule in this example.
Separate variation around a mean from error around a target
A target position is not necessarily the true process mean. Squared deviations about a fixed target capture both spread and displacement of the mean from the target. For example, the same readings have a sample mean of 4 micrometers. Relative to a target of 3, their deviations are -1, 1, and 3, and their mean squared error is 11/3 square micrometers. That number answers a different question from the variance around the sample mean. A report can include both, along with the definition of the target and the units.
A second invented run with readings [12, 14, 16] has the same variance as the first run. Every reading moved by the same amount, so each deviation from that run's own mean is identical. Yet its mean is now 14 micrometers. This is why a low spread can coexist with a large offset, and why the mean and target error are worth keeping beside a repeatability estimate.
translated = readings + 10.
assert np.var(translated, ddof=1) == estimated
assert np.mean(translated) - np.mean(readings) == 10.
assert np.mean((readings - 3.) ** 2) == 11 / 3
The denominator choice also does not address drift, dependence among consecutive readings, or missing values that correlate with measurement size. Those conditions can change what a run says about the longer process. Keep test segments associated with their acquisition settings, and document the basis for treating them as samples of one process. If a report excludes readings, preserve the exclusion rule and valid count with the result.
Include units and the denominator in the record
Report variance in squared units. Use standard deviation when a reader needs a summary in the original units, and calculate it from the variance convention used in the report. An example validation checks a complete channel against a hand calculation, one channel with a missing reading, and channels with one or zero valid readings. Save the channel identity, observation count, and denominator convention together so a later tool can reproduce the same quantity.
Sources checked November 28, 2026
NumPy, numpy.var
https://numpy.org/doc/stable/reference/generated/numpy.var.html
NumPy, numpy.nanvar
https://numpy.org/doc/stable/reference/generated/numpy.nanvar.html
Python 3.14 documentation, statistics
https://docs.python.org/3.14/library/statistics.html
Illustration. AI-generated concept showing the two variance denominators applied to the same set of observations.