Version: | 1.0.6 |
Date: | 2025-09-03 |
Title: | Precision Profile Weighted Deming Regression |
Author: | Douglas M. Hawkins [aut], 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; functions are provided for implementing it in both known and unknown precision profile situations. The package provides tools for precision profile weighted Deming (PWD) regression. It 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 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. Further information on mathematical derivations and applications can be found on arXiv: Hawkins and Kraker (2025) <doi:10.48550/arXiv.2508.02888>. |
License: | GPL (≥ 3) |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2 |
Config/testthat/edition: | 3 |
NeedsCompilation: | no |
Packaged: | 2025-09-04 11:36:08 UTC; jjkra |
Repository: | CRAN |
Date/Publication: | 2025-09-09 14:20: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, epsilon=1e-6)
Arguments
X |
the vector of predicate readings, |
Y |
the vector of test readings, |
sigma |
the RL sigma parameter, |
kappa |
the RL kappa parameter, |
lambda |
optional (default of 1) - the ratio of the X to the Y precision profile, |
epsilon |
optional - 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 |
like |
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. Precision Profile Weighted Deming Regression for Methods Comparison, on Arxiv (2025) doi:10.48550/arXiv.2508.02888
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, epsilon=1.e-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 X to the Y precision profile (defaults to 1), |
epsilon |
optional (default of 1.e-8) - convergence tolerance limit, |
printem |
optional - 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
.
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 |
like |
the -2 log likelihood L |
Author(s)
Douglas M. Hawkins, Jessica J. Kraker krakerjj@uwec.edu
References
Hawkins DM and Kraker JJ. Precision Profile Weighted Deming Regression for Methods Comparison, on Arxiv (2025) doi:10.48550/arXiv.2508.02888
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))
Weighted Deming Regression – Inference
Description
This routine fits the regression, uses the jackknife to get its precision, and optionally prints it out. Currently implements Rocke-Lorenzato as the variance profile model.
Usage
PWD_inference(X, Y, lambda=1, 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 X to the Y precision profile. |
MDL |
optional (default to missing) - medical decision level(s), |
epsilon |
optional (default of 1.e-8) - convergence tolerance limit, |
printem |
optional - 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 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 |
like |
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. Precision Profile Weighted Deming Regression for Methods Comparison, on Arxiv (2025) doi:10.48550/arXiv.2508.02888
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-10,
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 convergence tolerance limit, |
MDL |
optional medical decision level(s), |
getCI |
optional - allows for jackknifed standard errors on the regression and MDL, |
printem |
optional - 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 |
like |
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),
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, 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 the ratio of the X to the Y precision profile (defaults to 1), |
Pcut |
optional, default 0.01 (1%), cutoff for statistical significance of Bonferroni P, |
printem |
optional - 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 assume normality of the predicted 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 |
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. Precision Profile Weighted Deming Regression for Methods Comparison, on Arxiv (2025) doi:10.48550/arXiv.2508.02888
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 (via PWD_inference
).
Usage
PWD_resi(true, resi, epsilon=1e-5, 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-5) - convergence tolerance limit, |
printem |
optional - 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.
This function includes a check for the special cases of
constant variance (
\kappa_r=0
) - in this case, one could switch to the simpler unweighted Deming model;and of constant coefficient of variation (
\sigma_r=0
) - in this case, one could switch to the constant CV weighted Deming model.
using chi-squared tests.
Value
A list containing the following components:
sigmar |
the estimate of |
kappar |
the estimate of |
like |
the likelihood |
scalr |
the scaled residuals |
poolsig |
the maximum likelihood estimate of |
poolkap |
the maximum likelihood estimate of |
tests |
the chi-squared test statistics for |
Pvals |
the P values for the two chi-squared tests |
Author(s)
Douglas M. Hawkins, Jessica J. Kraker krakerjj@uwec.edu
References
Hawkins DM and Kraker JJ. Precision Profile Weighted Deming Regression for Methods Comparison, on Arxiv (2025) doi:10.48550/arXiv.2508.02888
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,printem=FALSE)
# 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-10)
Arguments
X |
the vector of predicate readings, |
Y |
the vector of test readings, |
g |
the vector of variances of the X, |
h |
the vector of variances of the Y, |
epsilon |
optional convergence tolerance limit. |
Details
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 X and Y |
fity |
the vector of predicted Y |
mu |
the vector of estimated latent true values |
resi |
the vector of residuals |
like |
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-9, 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 medical decision limit(s), |
getCI |
if TRUE, generates jackknife standard errors, |
epsilon |
optional tolerance limit, |
printem |
if TRUE, prints out results as a |
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")