| Version: | 2.0.0 |
| Date: | 2025-12-21 |
| Title: | Precision Profile Weighted Deming Regression |
| Author: | Douglas M. Hawkins [aut, cph], Jessica J. Kraker [aut, cre] |
| Maintainer: | Jessica J. Kraker <krakerjj@uwec.edu> |
| Depends: | R (≥ 3.6.0) |
| Suggests: | testthat (≥ 3.0.0) |
| Imports: | stats |
| Description: | Weighted Deming regression, also known as 'errors-in-variable' regression, is applied with suitable weights. Weights are modeled via a precision profile; thus the methods implemented here are referred to as precision profile weighted Deming (PWD) regression. The package covers two settings – one where the precision profiles are known either from external studies or from adequate replication of the X and Y readings, and one in which there is a plausible functional form for the precision profiles but the exact (unknown) function must be estimated from the (generally singlicate) readings. The function set includes tools for: estimated standard errors (via jackknifing); standardized-residual analysis function with regression diagnostic tools for normality, linearity and constant variance; and an outlier analysis identifying significant outliers for closer investigation. The following reference provides further information on mathematical derivations and applications. Hawkins, D.M., and J.J. Kraker. 'Precision Profile Weighted Deming Regression for Methods Comparison', (in press) <doi:10.1093/jalm/jfaf183>. |
| License: | GPL (≥ 3) |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.2 |
| Config/testthat/edition: | 3 |
| NeedsCompilation: | no |
| Packaged: | 2026-01-09 21:50:51 UTC; jjkra |
| Repository: | CRAN |
| Date/Publication: | 2026-01-09 22:10:02 UTC |
Weighted Deming – Rocke-Lorenzato - known sigma, kappa
Description
This code fits the weighted Deming regression on
predicate readings (X) and test readings (Y),
with user-supplied Rocke-Lorenzato ("RL") parameters
sigma (\sigma) and kappa (\kappa).
Usage
PWD_RL(X, Y, sigma, kappa, lambda=1, alpha=NA, beta=NA, mu=NA, epsilon=1e-8)
Arguments
X |
the vector of predicate readings. |
Y |
the vector of test readings. |
sigma |
the RL |
kappa |
the RL |
lambda |
optional (default of 1) - the ratio of the |
alpha |
optional (default of NA) - numeric, single value, initial estimate of |
beta |
optional (default of NA) - numeric, single value, initial estimate of |
mu |
optional (default of NA) - numeric, vector of length of |
epsilon |
optional (default of 1e-8) - convergence tolerance limit. |
Details
The Rocke-Lorenzato precision profile model assumes the following
forms for the variances, with proportionality constant \lambda:
predicate precision profile model:
g_i = var(X_i) = \lambda\left(\sigma^2 + \left[\kappa\cdot \mu_i\right]^2\right)andtest precision profile model:
h_i = var(Y_i) = \sigma^2 + \left[\kappa\cdot (\alpha + \beta\mu_i)\right]^2.
The algorithm uses maximum likelihood estimation. Proportionality constant
\lambda is assumed to be known or estimated externally.
Value
A list containing the following components:
alpha |
the fitted intercept |
beta |
the fitted slope |
fity |
the vector of predicted Y |
mu |
the vector of estimated latent true values |
resi |
the vector of residuals |
L |
the -2 log likelihood L |
innr |
the number of inner refinement loops executed |
error |
an error code if the iteration fails |
Author(s)
Douglas M. Hawkins, Jessica J. Kraker krakerjj@uwec.edu
References
Hawkins DM and Kraker JJ (in press). Precision Profile Weighted Deming Regression for Methods Comparison. The Journal of Applied Laboratory Medicine. doi:10.1093/jalm/jfaf183
Hawkins DM (2014). A Model for Assay Precision. Statistics in Biopharmaceutical Research, 6, 263-269. doi:10.1080/19466315.2014.899511
Examples
# library
library(ppwdeming)
# parameter specifications
sigma <- 1
kappa <- 0.08
alpha <- 1
beta <- 1.1
true <- 8*10^((0:99)/99)
truey <- alpha+beta*true
# simulate single sample - set seed for reproducibility
set.seed(1039)
# specifications for predicate method
X <- sigma*rnorm(100)+true *(1+kappa*rnorm(100))
# specifications for test method
Y <- sigma*rnorm(100)+truey*(1+kappa*rnorm(100))
# fit RL with given sigma and kappa
RL_results <- PWD_RL(X,Y,sigma,kappa)
cat("\nWith given sigma and kappa, the estimated intercept is",
signif(RL_results$alpha,4), "and the estimated slope is",
signif(RL_results$beta,4), "\n")
Estimate of Variance Profile Functions (proportional)
Description
This code estimates the variance profiles, assumed proportional, of the Rocke-Lorenzato form; also provides the resulting weighted Deming fit and residuals.
Usage
PWD_get_gh(X, Y, lambda = 1, rho=NA, alpha=NA, beta=NA, mu=NA,
epsilon = 1e-8, printem=FALSE)
Arguments
X |
the vector of predicate readings. |
Y |
the vector of test readings. |
lambda |
optional (default of 1) - the ratio of the |
rho |
optional (default of NA) - numeric, single value or vector, initial estimate(s) of |
alpha |
optional (default of NA) - numeric, single value, initial estimate of |
beta |
optional (default of NA) - numeric, single value, initial estimate of |
mu |
optional (default of NA) - numeric, vector of length of |
epsilon |
optional (default of 1.e-8) - convergence tolerance limit. |
printem |
optional (default of FALSE) - if TRUE, routine will print out results as a |
Details
This workhorse routine optimizes the likelihood in the unknown g, h
setting over its n+4 parameters
(the two Rocke-Lorenzato precision profile parameters \sigma
and \kappa, the intercept \alpha and slope \beta,
and the n latent true concentrations \mu_i).
That is, the assumed forms are:
predicate precision profile model:
g_i = var(X_i) = \lambda\left(\sigma^2 + \left[\kappa\cdot \mu_i\right]^2\right)andtest precision profile model:
h_i = var(Y_i) = \sigma^2 + \left[\kappa\cdot (\alpha + \beta\mu_i)\right]^2.
The search algorithm implements an efficient approach via reparameterization
to the ratio \rho = \frac{\sigma}{\kappa}.
If initial estimates are not provided, the parameters are initialized as:
-
alphaandbetaare initially intercept and slope from simple linear regression; -
rhois initialized as the vector c(0.01, 1, 100); and -
muis initialized as the values ofX.
Value
A list containing the following components:
alpha |
the fitted intercept |
beta |
the fitted slope |
fity |
the vector of predicted Y |
mu |
the vector of estimated latent true values |
resi |
the vector of residuals |
sigma |
the estimate of the Rocke-Lorenzato |
kappa |
the estimate of the Rocke-Lorenzato |
L |
the -2 log likelihood L |
Author(s)
Douglas M. Hawkins, Jessica J. Kraker krakerjj@uwec.edu
References
Hawkins DM and Kraker JJ (in press). Precision Profile Weighted Deming Regression for Methods Comparison. The Journal of Applied Laboratory Medicine. doi:10.1093/jalm/jfaf183
Rocke DM, Lorenzato S (2012). A Two-Component Model for Measurement Error in Analytical Chemistry. Technometrics, 37:2:176-184.
Examples
# library
library(ppwdeming)
# parameter specifications
sigma <- 1
kappa <- 0.08
alpha <- 1
beta <- 1.1
true <- 8*10^((0:99)/99)
truey <- alpha+beta*true
# simulate single sample - set seed for reproducibility
set.seed(1039)
# specifications for predicate method
X <- sigma*rnorm(100)+true *(1+kappa*rnorm(100))
# specifications for test method
Y <- sigma*rnorm(100)+truey*(1+kappa*rnorm(100))
# fit with RL precision profile to estimate parameters
RL_gh_fit <- PWD_get_gh(X,Y,printem=TRUE)
# RL precision profile estimated parameters
cat("\nsigmahat=", signif(RL_gh_fit$sigma,6),
"and kappahat=", signif(RL_gh_fit$kappa,6), "\n")
# with estimated linear coefficients
cat("\nalphahat=", signif(RL_gh_fit$alpha,6),
"and betahat=", signif(RL_gh_fit$beta,6), "\n")
Weighted Deming Regression – Inference
Description
This routine fits the regression, uses the jackknife to get its precision, and optionally prints it out. Implements Rocke-Lorenzato as the variance profile model.
Usage
PWD_inference(X, Y, lambda=1, rho=NA, alpha=NA, beta=NA, mu=NA, MDL=NA,
epsilon=1e-8, printem=FALSE)
Arguments
X |
the vector of predicate readings. |
Y |
the vector of test readings. |
lambda |
optional (default of 1) - the ratio of the |
rho |
optional (default of NA) - numeric, single value or vector, initial estimate(s) of |
alpha |
optional (default of NA) - numeric, single value, initial estimate of |
beta |
optional (default of NA) - numeric, single value, initial estimate of |
mu |
optional (default of NA) - numeric, vector of length of |
MDL |
optional (default to missing) - medical decision level(s). |
epsilon |
optional (default of 1.e-8) - convergence tolerance limit. |
printem |
optional (default of FALSE) - if TRUE, routine will print out results as a |
Details
For the linear model relating the predicate and test readings,
the standard errors of the estimators \hat{\alpha},
\hat{\beta}, and their covariance are estimated by
the jackknife. The point estimates of the intercept and slope are output,
along with their standard errors and covariance.
These estimates are further used
to estimate the predictions at the input MDL.
Value
A list containing the following components:
alpha |
the fitted intercept |
beta |
the fitted slope |
cor |
the Pearson correlation between X and Y |
fity |
the vector of predicted Y |
mu |
the vector of estimated latent true values |
resi |
the vector of residuals |
preresi |
the vector of leave-one-out predicted residuals |
sigma |
the estimate of the Rocke-Lorenzato |
kappa |
the estimate of the Rocke-Lorenzato |
L |
the -2 log likelihood L |
sealpha |
the jackknife standard error of alpha |
sebeta |
the jackknife standard error of beta |
covar |
the jackknife covariance between alpha and beta |
preMDL |
the predictions at the MDL(s) |
preMDLl |
the lower confidence limit(s) of preMDL |
preMDLu |
the upper confidence limit(s) of preMDL |
Author(s)
Douglas M. Hawkins, Jessica J. Kraker krakerjj@uwec.edu
References
Hawkins DM and Kraker JJ (in press). Precision Profile Weighted Deming Regression for Methods Comparison. The Journal of Applied Laboratory Medicine. doi:10.1093/jalm/jfaf183
Efron, B (1982). The jackknife, the bootstrap and other resampling plans. Society for Industrial and Applied Mathematics.
Examples
# library
library(ppwdeming)
# parameter specifications
sigma <- 1
kappa <- 0.08
alpha <- 1
beta <- 1.1
true <- 8*10^((0:99)/99)
truey <- alpha+beta*true
# simulate single sample - set seed for reproducibility
set.seed(1039)
# specifications for predicate method
X <- sigma*rnorm(100)+true *(1+kappa*rnorm(100))
# specifications for test method
Y <- sigma*rnorm(100)+truey*(1+kappa*rnorm(100))
# fit with RL precision profile to estimate parameters and variability
RL_inf <- PWD_inference(X,Y,MDL=12,printem=TRUE)
Weighted Deming Regression – general weights
Description
This code is used for the setting of known precision profiles implemented
in user-provided R functions called gfun and hfun.
Usage
PWD_known(X, Y, gfun, hfun, gparms, hparms, epsilon=1e-8,
MDL=NA, getCI=TRUE, printem=FALSE)
Arguments
X |
the vector of predicate readings. |
Y |
the vector of test readings. |
gfun |
a function with two arguments, a vector of size n and a vector of parameters. |
hfun |
a function with two arguments, a vector of size n and a vector of parameters. |
gparms |
a numeric vector containing any parameters referenced by |
hparms |
a numeric vector containing any parameters referenced by |
epsilon |
optional (default of 1.e-8) - convergence tolerance limit. |
MDL |
optional (default of NA) - medical decision level(s). |
getCI |
optional (default of TRUE) - allows for jackknifed standard errors on the regression and MDL. |
printem |
optional (default of FALSE) - if TRUE, routine will print out results as a |
Details
The functions gfun and hfun are allowed as inputs,
to support flexibility in specification of the forms of these variance functions.
The known precision profiles specified by the functions gfun and hfun,
when provided with estimated vectors of \mu and \alpha + \beta\mu
respectively and with any required parameters, will produce
the vectors g and h. These vectors are then integrated into the
iterative estimation of the slope and intercept of the linear relationship
between predicate and test readings.
Value
A list containing the following components:
alpha |
the fitted intercept |
beta |
the fitted slope |
cor |
the Pearson correlation between X and Y |
fity |
the vector of predicted Y |
mu |
the vector of estimated latent true values |
resi |
the vector of residuals |
scalr |
the vector of scaled residuals using the specified g and h |
L |
the -2 log likelihood L |
sealpha |
the jackknife standard error of alpha |
sebeta |
the jackknife standard error of beta |
covar |
the jackknife covariance between alpha and beta |
preMDL |
the predictions at the MDL(s) |
preMDLl |
the lower confidence limit(s) of preMDL |
preMDLu |
the upper confidence limit(s) of preMDL |
Author(s)
Douglas M. Hawkins, Jessica J. Kraker krakerjj@uwec.edu
Examples
# library
library(ppwdeming)
# parameter specifications
alpha <- 1
beta <- 1.1
true <- 8*10^((0:99)/99)
truey <- alpha+beta*true
# forms of precision profiles
gfun <- function(true, gparms) {
gvals = gparms[1]+gparms[2]*true^gparms[3]
gvals
}
hfun <- function(true, hparms) {
hvals = hparms[1]+hparms[2]*true^hparms[3]
hvals
}
# Loosely motivated by Vitamin D data set
g <- 4e-16+0.07*true^1.27
h <- 6e-2+7e-5*truey^2.2
# simulate single sample - set seed for reproducibility
set.seed(1039)
# specifications for predicate method
X <- true +sqrt(g)*rnorm(100)
# specifications for test method
Y <- truey+sqrt(h)*rnorm(100)
# fit with to estimate linear parameters
pwd_known_fit <- PWD_known(X, Y, gfun, hfun,
gparms=c(4e-16, 0.07, 1.27),
hparms=c(6e-2, 7e-5, 2.2), MDL=12,
printem=TRUE)
Weighted Deming Regression – Outlier scanning
Description
This function tests for outliers from the fitted regression, and refits on a sanitized data set (with outliers removed).
Usage
PWD_outlier(X, Y, K, lambda=1, Pcut=0.01, rho=NA, alpha=NA, beta=NA, mu=NA,
printem=FALSE)
Arguments
X |
the vector of predicate readings. |
Y |
the vector of test readings. |
K |
the maximum number of outliers to seek. |
lambda |
optional (default of 1) - the ratio of the |
Pcut |
optional, default 0.01 (1%), cutoff for statistical significance of Bonferroni P. |
rho |
optional (default of NA) - numeric, single value or vector, initial estimate(s) of |
alpha |
optional (default of NA) - numeric, single value, initial estimate of |
beta |
optional (default of NA) - numeric, single value, initial estimate of |
mu |
optional (default of NA) - numeric, vector of length of |
printem |
optional (default of FALSE) - if TRUE, routine will print out results as a |
Details
The method is modeled on the Rosner sequential ESD outlier procedure and assumes the sample is large enough to ignore the effect of random variability in the parameter estimates on the distribution of the residuals.
Value
A list containing the following components:
ndrop |
the number of significant outliers |
drop |
a vector of the indices of the outliers |
cor |
the Pearson correlation between X and Y |
cleancor |
the Pearson correlation between cleaned X and Y (after outliers removed) |
scalr |
the scaled residuals of all cases from the sanitized fit and whose normal tail areas provide the basis for the outlier P values |
keep |
logical vector identifying which cases retained in sanitized data set |
basepar |
the sigma, kappa, alpha, beta of the full data set |
lastpar |
the sigma, kappa, alpha, beta of the sanitized data set |
Author(s)
Douglas M. Hawkins, Jessica J. Kraker krakerjj@uwec.edu
References
Hawkins DM and Kraker JJ (in press). Precision Profile Weighted Deming Regression for Methods Comparison. The Journal of Applied Laboratory Medicine. doi:10.1093/jalm/jfaf183
Hawkins DM (2008). Outliers in Wiley Encyclopedia of Clinical Trials, eds R. D’Agostino, L. Sullivan, and J. Massaro. Wiley, New York.
Examples
# library
library(ppwdeming)
# parameter specifications
sigma <- 1
kappa <- 0.08
alpha <- 1
beta <- 1.1
true <- 8*10^((0:99)/99)
truey <- alpha+beta*true
# simulate single sample - set seed for reproducibility
set.seed(1039)
# specifications for predicate method
X <- sigma*rnorm(100)+true *(1+kappa*rnorm(100))
# specifications for test method
Y <- sigma*rnorm(100)+truey*(1+kappa*rnorm(100))
# add some outliers
Y[c(1,2,100)] <- Y[c(1,2,100)] + c(7,4,-45)
# check for outliers, re-fit, and store output
outliers_assess <- PWD_outlier(X, Y, K=5, printem=TRUE)
Fit Rocke-Lorenzato profile model to residuals
Description
This routine fits the Rocke-Lorenzato precision profile model to the residuals from the fit.
Usage
PWD_resi(true, resi, epsilon=1e-8, printem=FALSE)
Arguments
true |
the vector of values used to predict the precision – commonly X. |
resi |
the vector of residuals whose variance is thought to be a function of “true”. |
epsilon |
optional (default of 1e-8) - convergence tolerance limit. |
printem |
optional (default of FALSE) - if TRUE, routine will print out results as a |
Details
The Rocke-Lorenzato precision profile model is
SD^2 = \sigma_r^2 + (\kappa_r\cdot true)^2
for the residuals from a precision-profile model fit.
Under this model, the approach for reviewing residuals is to fit a
variance profile model to the residuals r_i themselves. The output
of this function includes a maximum-likelihood estimate of the remaining
parameter in the special cases of:
constant variance (
\kappa_r= 0); andconstant coefficient of variation (
\sigma_r= 0).
Value
A list containing the following components:
sigmar |
the estimate of |
kappar |
the estimate of |
L |
the -2 log likelihood |
scalr |
the scaled residuals |
poolsig |
the maximum likelihood estimate of |
poolkap |
the maximum likelihood estimate of |
Author(s)
Douglas M. Hawkins, Jessica J. Kraker krakerjj@uwec.edu
References
Hawkins DM and Kraker JJ (in press). Precision Profile Weighted Deming Regression for Methods Comparison. The Journal of Applied Laboratory Medicine. doi:10.1093/jalm/jfaf183
Hawkins DM (2014). A Model for Assay Precision. Statistics in Biopharmaceutical Research, 6, 263-269. http://dx.doi.org/10.1080/19466315.2014.899511
Examples
# library
library(ppwdeming)
# parameter specifications
sigma <- 1
kappa <- 0.08
alpha <- 1
beta <- 1.1
true <- 8*10^((0:99)/99)
truey <- alpha+beta*true
# simulate single sample - set seed for reproducibility
set.seed(1039)
# specifications for predicate method
X <- sigma*rnorm(100)+true *(1+kappa*rnorm(100))
# specifications for test method
Y <- sigma*rnorm(100)+truey*(1+kappa*rnorm(100))
# fit the model and store output
RL_gh_fit <- PWD_get_gh(X,Y)
# run the residual analysis from the model output
post <- PWD_resi(X, RL_gh_fit$resi, printem=TRUE)
Weighted Deming Regression
Description
This code fits the weighted Deming regression on predicate readings (X) and test readings (Y).
Usage
WD_General(X, Y, g, h, epsilon=1e-8)
Arguments
X |
the vector of predicate readings. |
Y |
the vector of test readings. |
g |
the vector of variances of the |
h |
the vector of variances of the |
epsilon |
optional (default of 1e-8) - convergence tolerance limit. |
Details
This function is used when the variances of X and Y are already known,
as can be the case from an adequate number of replicate X and Y readings
of each sample. For input vectors g and h containing the variances of
predicate readings X and test readings Y, respectively, iteratively fits
weighted Deming regression.
Value
A list containing the following components:
alpha |
the fitted intercept |
beta |
the fitted slope |
cor |
the Pearson correlation between |
fity |
the vector of predicted Y |
mu |
the vector of estimated latent true values |
resi |
the vector of residuals |
L |
the -2 log likelihood L |
innr |
the number of inner refinement loops executed |
Author(s)
Douglas M. Hawkins, Jessica J. Kraker krakerjj@uwec.edu
References
Ripley BD and Thompson M (1987). Regression techniques for the detection of analytical bias. Analyst, 112, 377-383.
Examples
# library
library(ppwdeming)
# parameter specifications
alpha <- 1
beta <- 1.1
true <- 8*10^((0:99)/99)
truey <- alpha+beta*true
# Loosely motivated by Vitamin D data set
g <- 4e-16+0.07*true^1.27
h <- 6e-2+7e-5*truey^2.2
# simulate single sample - set seed for reproducibility
set.seed(1039)
# specifications for predicate method
X <- true +sqrt(g)*rnorm(100)
# specifications for test method
Y <- truey+sqrt(h)*rnorm(100)
# fit with to estimate linear parameters
wd_fit <- WD_General(X,Y,g,h)
cat("\nWith given g and h, the estimated intercept is",
signif(wd_fit$alpha,4), "and the estimated slope is",
signif(wd_fit$beta,4), "\n")
Linnet proportional CV weighted Deming
Description
This routine, provided for convenience, makes Linnet’s constant CV fit.
Usage
WD_Linnet(X, Y, lambda=1, MDL=NA, getCI=TRUE, epsilon=1e-10, printem=FALSE)
Arguments
X |
the vector of predicate readings. |
Y |
the vector of test readings. |
lambda |
ratio of g function to h function. |
MDL |
optional (default of NA) - medical decision limit(s). |
getCI |
optional (default of TRUE) - if TRUE, generates jackknife standard errors. |
epsilon |
optional (default of 1e-10) - tolerance limit. |
printem |
optional (default of FALSE) - if TRUE, prints out results as a |
Details
Note that in cases where sigma happens to come out zero, Linnet’s constant CV fit differs from the precision-profile fit since the underlying precision profile models are not the same.
Value
A list containing the following components:
alpha |
the fitted intercept |
beta |
the fitted slope |
cor |
the Pearson correlation between X and Y |
sealpha |
the jackknife standard error of alpha |
sebeta |
the jackknife standard error of beta |
covar |
the jackknife covariance between alpha and beta |
preMDL |
the predictions at the MDL(s) |
preMDLl |
the lower confidence limit(s) of preMDL |
preMDLu |
the upper confidence limit(s) of preMDL |
Author(s)
Douglas M. Hawkins, Jessica J. Kraker krakerjj@uwec.edu
References
Linnet K (1993). Evaluation of regression procedures for methods comparison studies. Clinical Chemistry, 39: 424-432.
Examples
# library
library(ppwdeming)
# parameter specifications
alpha <- 1
beta <- 1.1
true <- 8*10^((0:99)/99)
truey <- alpha+beta*true
kappa <- 0.1
# simulate single sample - set seed for reproducibility
set.seed(1039)
# specifications for predicate method
X <- true *(1+kappa*rnorm(100))
# specifications for test method
Y <- truey *(1+kappa*rnorm(100))
# fit with to estimate linear parameters
wd_fit <- WD_Linnet(X, Y, MDL=12, printem=TRUE)
cat("\nThe Linnet constant-CV estimated intercept is",
signif(wd_fit$alpha,4), "and the estimated slope is",
signif(wd_fit$beta,4), "\n")