
Measurement error in assay data: what the weights mean
An additive model, reliability, censoring, and a glossary for immunologists
Source:vignettes/measurement-error.Rmd
measurement-error.RmdWho this is for. You know linear models, random
effects and likelihoods, and you know your assay. You have not
necessarily met measurement-error models, the branch of
statistics that separates “the sample really differs” from “the assay
read it imprecisely”. This page explains the one idea you need, how
curveRweights uses it, and which numbers it hands you. A companion page,
vignette("downstream-analysis"), shows what to do with
those numbers.
The one idea: every reading is signal plus noise
Take one serum sample measured on a bead assay. The number you report, the back-calculated log10 concentration , is built from three things:
- is the group mean, for example a vaccine arm at one time point. Estimating differences in is usually the scientific question.
- is true biological variation between people (or between samples): some people simply respond more strongly. It has variance . More assay precision never removes it.
-
is measurement error. The calibration curve tells us
how large it is for this sample: the standard error
seof the back-calculated concentration, so . Near the top and bottom of the standard curve the curve is flat, a small change in the signal means a large change in concentration, and is large. In the middle is small.
Because and are independent, their variances add:
This is the additive model. It is the same structure as a random-effects meta-analysis, where each study has a within-study variance (known) and the studies differ by a between-study variance (estimated).
Why we weight at all
A weighted analysis gives precisely measured samples more say. The efficient weight is the inverse of the total variance:
Look at what this does at the extremes:
- A hopelessly noisy sample () gets weight near 0. Good.
- A perfectly measured sample () gets weight , not infinity. Good: a perfect measurement of one person still tells you only about that person, and people differ by .
So the largest weight ratio you can ever see is bounded: .
Additive versus multiplicative
Versions of curveRweights before 0.3.0 used a multiplicative model, , so . Here all the variance is attributed to the measurement. A sample with a very small then gets a very large weight, with no ceiling, even when real person-to-person variation (the above) would limit what that sample can tell you. The additive model puts a floor under and therefore a ceiling on .
The simulation below uses the same values for both. The true model is additive with ; we ask each approach what weights it implies.
set.seed(42)
se <- exp(rnorm(2000, log(0.15), 0.9)) # a realistic spread of SEs
tau <- 0.4
w_add <- 1 / (tau^2 + se^2) # additive: ceiling 1/tau^2 = 6.25
w_mult <- 1 / (1.1^2 * se^2) # multiplicative, phi = 1.1
ratio <- function(w) max(w) / min(w)
c(additive = ratio(w_add), multiplicative = ratio(w_mult))
#> additive multiplicative
#> 90.15707 274173.78492
c(`additive ceiling 1/tau^2` = 1 / tau^2,
`multiplicative max weight` = max(w_mult))
#> additive ceiling 1/tau^2 multiplicative max weight
#> 6.25 15878.96With the SE spread used here the multiplicative weights span a ratio of hundreds of thousands, against about 90 for the additive model, and its largest weight (about 16,000) is thousands of times the additive ceiling of 6.25. In a real analysis such a sample effectively is the group mean. That is the practical reason the additive model is the one to prefer when you analyse differences between people or groups and when between-subject variation is not negligible.
Which model do I get? fit_precision_weights() still
defaults to model = "multiplicative" so that existing
pipelines and results are unchanged; ask for the new one with
model = "additive". In I-SPI the choice is recorded with
every weight set (column model).
| Situation | Prefer |
|---|---|
| Comparing groups or time points; people differ a lot | additive |
| Assay noise dominates and people barely differ () | either; they agree |
| You must reproduce an earlier analysis | the model you used then |
Reliability: how much of what you see is real
The additive model gives each sample a reliability
It is the fraction of that sample’s variance that is genuine biological signal. If you know the intraclass correlation (ICC) from repeated-measures work or from the Cronbach’s of a questionnaire, this is the same idea applied sample by sample: 0.9 means “mostly signal”, 0.3 means “mostly assay noise”.
d <- data.frame(se_meas = c(0.03, 0.10, 0.30, 1.00))
out <- compute_additive_weights(d, tau2 = 0.16, kappa = 1)
out[, c("se_meas", "v_meas", "w", "reliability", "w_norm")]
#> se_meas v_meas w reliability w_norm
#> 1 0.03 9e-04 6.215040 0.9944065 1.4658579
#> 2 0.10 1e-02 5.882353 0.9411765 1.3873914
#> 3 0.30 9e-02 4.000000 0.6400000 0.9434261
#> 4 1.00 1e+00 0.862069 0.1379310 0.2033246Reliability is the number to show to collaborators. A weight depends on an arbitrary scale; a reliability does not. It also explains regression dilution, below.
Two cautions when you report it:
-
Which variation counts as signal depends on the
model. When the fit includes a subject random intercept (the
default whenever a
patientidcolumn is present; see Repeated measures), differences between people go into that intercept, and is the variation that remains within a person once the design cell is accounted for. The reliability is then a within-person reliability: how much of the change from one sample to the next, for the same person, is real. -
Reliability belongs to the calibration that produced the
se. The same samples calibrated with the Bayesian and the frequentist curve fit have differentsevalues, and the model’s split of the variance follows these. In one real data set the Bayesiansevaried much less from sample to sample than the frequentistsedid, although the scatter of the readings was the same; the fit needed for the Bayesianse(against 1.5), and the median reliability was 0.04 against 0.64. Compare reliabilities only within one calibration method.
Weights fix efficiency, not bias in predictors
Weights improve the precision of an estimate when the noisy variable is the outcome. When the noisy variable is a predictor (for example antibody level used to predict infection, or one antigen’s response correlated with another’s), weights do not repair it. Noise in a predictor flattens the fitted slope toward zero by roughly the factor (regression dilution or attenuation). Two remedies are included:
# a correlation of 0.42 between two noisy assays with mean reliabilities 0.85, 0.70
attenuation_correct(0.42, rel_x = 0.85, rel_y = 0.70)
#> [1] 0.5444911reliability_correct() replaces each measured value by
its best prediction of the true value (shrinking it toward its cell mean
by
),
which removes the first-order bias of a regression slope. See
vignette("downstream-analysis") for a worked example.
Samples outside the standard curve: censoring
A sample whose signal falls below the lowest standard is not “a noisy concentration”. It is a sample we know only to be below some limit. Giving such a value an ordinary weight is wrong: its precision is poor because the concentration is extreme, so inverse-variance weights down-weight the very samples that say “low”, and group means drift towards the middle of the curve.
The additive model treats these samples as censored:
- left-censored: the true value is below the lower limit;
- right-censored: above the upper limit;
- interval: between two limits.
Quantified samples contribute the usual Normal density. A censored
sample contributes the probability of being beyond its limit,
so it informs the group mean and
without being treated as a precise point. In the weight table these rows
carry censor_type and bound, and their
w_norm is NA on purpose: represent them by the
bound, not by a weight.
set.seed(3)
n <- 20000
mu <- c(low = 0.6, high = 2.0)
g <- rep(names(mu), each = n)
tru <- rnorm(2 * n, rep(mu, each = n), 0.4)
se_fun <- function(y) 0.05 + 0.35 * plogis((0.5 - y) / 0.15) +
0.35 * plogis((y - 3.0) / 0.15)
obs <- tru + rnorm(2 * n, 0, se_fun(tru))
w <- 1 / (0.4^2 + se_fun(obs)^2) # additive weights, own-SE
rbind(truth = mu,
unweighted = tapply(obs, g, mean)[names(mu)],
weighted = tapply(obs * w, g, sum)[names(mu)] / tapply(w, g, sum)[names(mu)])
#> low high
#> truth 0.6000000 2.000000
#> unweighted 0.5964011 2.002382
#> weighted 0.6928282 1.995671Even with the additive ceiling the weighted mean of the low group
(about 0.69) sits well above the truth (0.60), while the unweighted mean
(0.60) does not; the high group is barely affected because most of it
lies where precision is good. That is the reason the package treats
out-of-range samples by their limits instead of weights.
prepare_censoring() builds the flags from curveRcore’s
censor_type, censor_lower and
censor_upper.
Repeated measures and dilutions
If the same patient contributes several samples, their
are not independent. fit_additive_weight() accepts a
patient column and adds a patient random intercept, the familiar
(1 | patientid), so the repeated measures are not
over-counted. fit_precision_weights() does this by default
when the data carry patientid; pass
patient_col = NA to leave it out.
With the patient term in the model, changes meaning: the stable person-to-person differences are absorbed by the patient intercept, and is the variation within a person (from one time point or sample to the next) that the design cell does not explain. Without the patient term, is the whole between-sample spread within a cell.
Dilutions or replicates of the same sample are not yet
handled well. A sample random intercept (sample_col in
fit_additive_weight()) absorbs the real between-sample
variation, which leaves
describing only the scatter between readings of one sample;
then tends to zero and the ceiling on the weights is lost. Until a
formulation that treats the sample term as the signal is available,
several readings of one sample count as separate observations, which
overstates how much independent information they carry.
Note on units: the weights are on the log10 concentration scale, the scale the model is fitted on. When censoring is used, the model puts the response on the final concentration scale (it adds ), the same scale as the censoring limits curveRcore reports.
What the stored columns mean
When I-SPI or the i-spi-compute worker saves weights, each sample row
(table calib_weights) holds:
| Column | Meaning |
|---|---|
model |
multiplicative or additive
|
se |
the calibration curve’s SE for that sample (measurement SD, log10) |
sigma |
total SD |
w |
raw inverse-variance weight |
w_norm |
w divided by its mean over quantified rows (mean 1).
NA for censored rows in the additive model |
v_meas |
measurement variance
(additive only). Use this for metafor
|
tau2 |
between-sample variance (additive only) |
reliability, _lo, _hi
|
and a 95% interval (additive only) |
censor_type, bound
|
none / left / interval / right, and the limit (log10) |
weights_pkg_version |
the curveRweights version that produced the row |
Per curve group (calib_weights_fit) you also get
,
,
the group mean reliability, n_censored, whether
was fixed, and an identifiability note. Column definitions live
in code too: curveRcore::weights_contract().
How good is ? Identifiability
(signal) and
(the scale of the measurement error) can be separated only because the
differ from sample to sample: when
is large, the total variance is mostly measurement; when small, mostly
.
If all
are nearly equal, the data cannot tell the two apart. By default
is fixed at 1 (the theoretical value from the delta method) and
is estimated. The fit reports a message when
is weakly identified; treat
and the reliabilities from such a group as provisional, or fix
with fix_kappa = TRUE and assume se is the
true measurement SD.
Reading
.
means the curve’s se is exactly the measurement SD. Values
between about 0.5 and 2 are common: the se captures the
shape of the precision profile but not its exact size (plate handling
and bead counts add noise the curve fit does not see). A
well above 2 says the readings scatter much more than their
se suggests, or that the se barely changes
between samples whose real precision differs; either way the
reliabilities rest heavily on
and should be read with care.
Checking a fit: the same diagnostics for both models
Both models are fitted the same way, as a Bayesian location-scale
model (one mean per design cell, a plate term, and a model for
)
sampled with Stan. Only the variance model differs. So both report the
same checks in $diagnostics, and the worker stores them in
calib_weights_fit:
| Entry | Question | Worry when |
|---|---|---|
rhat_max |
Did the chains agree? | above 1.05 |
n_divergent |
Could the sampler explore the posterior? | any |
ess_min |
Enough effective draws for stable intervals? | below about 400 |
ident_sd_ratio |
Did the data, not the prior, set (additive) or (multiplicative)? | above 0.8; above 1 suggests a sampling problem |
resid_sd |
Does the variance model fit the overall scatter? | far from 1 |
resid_sd_ratio |
Does it fit equally at low and high ? | far from 1 |
The residual check is the one that compares the models directly. Each
quantified sample’s scaled residual
should have SD 1 wherever
lies. resid_sd_ratio divides the (robust) SD of
in the
lowest-
fifth by that in the
highest-
fifth. When people really differ, the multiplicative model has no floor
for that variation: precisely measured samples scatter more than their
small
allows, the ratio rises above 1, and those samples get too much weight.
The additive model’s
is that floor.
A sampling problem (high R-hat, divergences, low ESS, or a posterior
wider than its prior) means the numbers cannot be relied on: run longer
chains (iter), and for the additive model consider
fix_kappa = TRUE, which removes the trade-off between
and
but moves any extra measurement error into
.
Glossary
| Term | Plain meaning |
|---|---|
| Measurement error | Difference between what the assay reports and the true value in that sample. |
| (standard error of concentration) | The curve’s own estimate of the measurement SD for one sample. |
| Signal variance | True person-to-person (sample-to-sample) variance in the quantity of interest. |
| Total variance | . |
| Weight | ; precisely measured samples count more, but never more than . |
| Reliability | ; fraction of the variance that is signal. Like an ICC. |
| Attenuation / regression dilution | A noisy predictor makes the fitted slope too flat by about . |
| Censoring | We know only that the value is below/above a limit. |
| Left / right / interval | Below the lower limit / above the upper limit / between two limits. |
| Identifiability | Whether the data contain enough information to tell two quantities apart. |
| REML | Restricted maximum likelihood; the standard estimator for variance components. |
| Delta method | A first-order approximation that converts the curve’s uncertainty into an SE for the concentration. |
Where next
-
vignette("downstream-analysis"): which analysis to run with these numbers. -
vignette("precision-weighting"): the multiplicative workflow in detail. - curveRfreq and curveRbayes: how the calibration curves, standard errors and censoring labels are produced (https://immunoplex.github.io/curveRfreq/, https://immunoplex.github.io/curveRbayes/).
- The page-by-page table of stored columns:
curveRcore::weights_contract().
Further reading
- Carroll RJ, Ruppert D, Stefanski LA, Crainiceanu CM. Measurement Error in Nonlinear Models, 2nd ed. Chapman & Hall/CRC, 2006. The standard textbook.
- Viechtbauer W. Conducting meta-analyses in R with the metafor package. J Stat Softw 2010;36(3).
- Hughes MD. Analysis and design issues for studies using censored biomarker measurements. Biometrics 2000;56:445-52. The case for handling values below detection limits by likelihood.
- Frost C, Thompson SG. Correcting for regression dilution bias: comparison of methods for a single predictor variable. J R Stat Soc A 2000;163:173-89.