Title: | Bayesian Deming Regression for Method Comparison |
Version: | 0.0.3 |
Maintainer: | Giorgio Pioda <gfwp@ticino.com> |
Description: | Regression methods to quantify the relation between two measurement methods are provided by this package. The focus is on a Bayesian Deming regressions family. With a Bayesian method the Deming regression can be run in a traditional fashion or can be run in a robust way just decreasing the degree of freedom d.f. of the sampling distribution. With d.f. = 1 an extremely robust Cauchy distribution can be sampled. Moreover, models for dealing with heteroscedastic data are also provided. For reference see G. Pioda (2024) https://piodag.github.io/bd1/. |
License: | GPL (≥ 3) |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.1 |
Biarch: | true |
Depends: | R (≥ 3.5.0) |
Imports: | methods, Rcpp (≥ 0.12.0), RcppParallel (≥ 5.0.1), rstan (≥ 2.18.1), rstantools (≥ 2.4.0), rrcov, mixtools, bayestestR, KernSmooth |
LinkingTo: | BH (≥ 1.66.0), Rcpp (≥ 0.12.0), RcppEigen (≥ 0.3.3.3.0), RcppParallel (≥ 5.0.1), rstan (≥ 2.18.1), StanHeaders (≥ 2.18.0) |
SystemRequirements: | GNU make |
NeedsCompilation: | yes |
Packaged: | 2024-07-26 13:45:42 UTC; gfwp |
Author: | Giorgio Pioda |
Repository: | CRAN |
Date/Publication: | 2024-07-26 14:30:07 UTC |
The 'rstanbdp' package.
Description
Bayesian Deming regression for Method Comparison
References
Stan Development Team (NA). RStan: the R interface to Stan. R package version 2.32.5. https://mc-stan.org _PATH
Plot the calculated Y response with CI from the full Bayesian posterior distribution
Description
Plot the calculated Y response with CI from the full Bayesian posterior distribution
Usage
bdpCalcResponse(bdpreg, Xval, ci = 0.95, ...)
Arguments
bdpreg |
bdpreg object |
Xval |
Reference method data |
ci |
Probability for the HDI credibility interval. Default 0.95. |
... |
Arguments passed to |
Value
no return
Extract relevant data from the Bayesian Deming regression
Description
Extract relevant data from the Bayesian Deming regression
Usage
bdpExtract(bdpreg)
Arguments
bdpreg |
bdpreg object created with bdpreg |
Value
A data frame with extracted data
Pairs plot of the full posterior predictors
Description
Pairs plot of the full posterior predictors
Usage
bdpPairs(bdpreg, ...)
Arguments
bdpreg |
bdpreg object created with bdpreg |
... |
Arguments passed to |
Value
Pairs plot of the stanfit
object
Plot Bayesian Deming regression and the confidence intervals from the full posterior distribution
Description
Plot Bayesian Deming regression and the confidence intervals from the full posterior distribution
Usage
bdpPlot(bdpreg, ci = 0.95, ...)
Arguments
bdpreg |
bdpreg object created with bdpreg |
ci |
Probability for the HDI credibility interval. Default 0.95 |
... |
Arguments passed to |
Value
no return
Plot regression posterior pairs with CI Box and MD ellipses
Description
Plot regression posterior pairs with CI Box and MD ellipses
Usage
bdpPlotBE(bdpreg, cov.method = "MCD", ci = 0.95, ...)
Arguments
bdpreg |
bdpreg object created with bdpreg |
cov.method |
rrcov covariance method ("SDe", "MCD", or "Classical"). Default MCD. |
ci |
Probability for the HDI credibility interval. Default 0.95. |
... |
Arguments passed to |
Value
no return
Plot studentized residuals from the Bayesian Deming regression
Description
Plot studentized residuals from the Bayesian Deming regression
Usage
bdpPlotResiduals(bdpreg, legend.pos = "bottomleft", legend.horizon = TRUE, ...)
Arguments
bdpreg |
bdpreg object created with bdpreg |
legend.pos |
Legend position (e.g. |
legend.horizon |
Legend |
... |
Arguments passed to |
Value
no return
Print summary of sampled data
Description
Print summary of sampled data
Usage
bdpPrint(bdpreg, digits_summary = 4, ...)
Arguments
bdpreg |
bdpreg object created with bdpreg |
digits_summary |
number of digits for the results |
... |
Arguments passed to |
Value
Print of the stanfit
object
Print summary of sampled data
Description
Print summary of sampled data
Usage
bdpSummary(bdpreg, ...)
Arguments
bdpreg |
bdpreg object created with bdpreg |
... |
Arguments passed to |
Value
Summary list of the stanfit
object
Plot a traceplot of the sampled chains
Description
Plot a traceplot of the sampled chains
Usage
bdpTraceplot(bdpreg, ...)
Arguments
bdpreg |
bdpreg object created with bdpreg |
... |
Arguments passed to |
Value
Traceplot of the stanfit
object
Bayesian Deming Pioda Regression for two method comparison with Rstan
Description
bdpreg
is used to compare two measurement methods by means of a Bayesian regression analysis.
Usage
bdpreg(
X,
Y,
ErrorRatio = 1,
df = NULL,
trunc = TRUE,
heteroscedastic = c("homo", "linear"),
slopeMu = 1,
slopeSigma = 0.3,
slopeTruncMin = 0.3333,
slopeTruncMax = 10,
interceptMu = 0,
interceptSigma = 30,
sigmaLambda = 0.3,
AlphaMu = 1,
AlphaSigma = 10,
BetaMu = 0.1,
BetaSigma = 0.5,
BetaTruncMin = -1,
BetaTruncMax = 1,
...
)
Arguments
X |
Numeric vector of input values. |
Y |
Numeric vector of output values. |
ErrorRatio |
Deming variance ratio between reference and test method. Default = 1. |
df |
Degree of freedom. Must be df >= 1 (robust Cauchy regression). Default is |
trunc |
Boolean. Default TRUE. Use truncated slope prior for stability with extreme ErrorRatios.
See |
heteroscedastic |
Bayesian Deming model choice. Alternatives are:
|
slopeMu |
Slope normal Mu prior value. Default 1. |
slopeSigma |
Slope normal Sigma prior value. Default 0.3. |
slopeTruncMin |
slope normal lower truncation limit. Default 0.3333. |
slopeTruncMax |
slope normal higher truncation limit. Default 10. |
interceptMu |
Intercept normal Mu prior value. Default 0. |
interceptSigma |
Intercept normal Sigma prior value. Default 30. |
sigmaLambda |
sigma exponential prior lambda. Default 0.3. |
AlphaMu |
Lin. heterosc. intercept normal mu prior. Must be > 0. Default 1. |
AlphaSigma |
Lin. heterosc. intercept normal sigma prior. Default 10. |
BetaMu |
Lin. heterosc. slope normal prior. Default 0.1. |
BetaSigma |
Lin. heterosc. slope normal prior. Default 0.5. |
BetaTruncMin |
Lin. heterosc. slope normal prior truncation min. Default -1. |
BetaTruncMax |
Lin. heterosc. slope normal prior truncation min. Default 1. |
... |
Arguments passed to |
Details
The Bayesian Deming regression can be run in a traditional fashion. In this case the error term is
sampled from a T
distribution with N-2
degree of freedom (N
sample size).
The Bayesian Deming regression can be run as a robust regression specifying a decreased df
parameter.
It is possible to set df = 1
and perform the sampling from an extremely robust Cauchy distribution
to suppress leveraged outliers. For moderate robustness a reasonably low value of df
in the interval
[6;10]
can be an appropriated choice.
ErrorRatio
can be set as usual for classical Deming regression. Default is 1. Strong
ErrorRatio
can lead to instability in the chains that may not converge after the burn in. For
this purpose the trunc
parameter can be used. In this way the normal distribution for the
slope gets truncated at a minimum of 0.3333 (default). The parameter slopeTruncMin
can override this value.
With the parameter heteroschedastic
it is possible to use an alternative regression which
models the heteroscedasticity with a linear growing variance. Alpha
and Beta
are the
intercept and the slope for the variance variation. Alpha
must be > 0. Beta
is usually
zero if no real heteroscedasticity is detected. Alternatively Beta
shows low positive values,
typically below 0.5 if heteroscedasticity is successfully modeled. The CI of Beta
could indeed
act as a test for heteroscedasticity. According to these empiric observations, Beta
is also
truncated to avoid erratic behavior of the Hamiltonian sampler.
The Bayesian Deming regression is recommended in many cases where traditional and non parametric method fail. It is particularly convenient with very small data set and/or with data set with low digit precision. In fact Bayesian Deming regression has no problem with ties.
The method with linear heteroscedastic fitting can be a meaningful answer to heteroscedastic
data set. The CI are much narrower and the trade off between robustness and power can find
a natural solution. It must be considered as highly experimental but also highly promising
method. Users are advised to carefully check the sampled output for undesirable correlation
between Alpha and/or Beta vs the slope and/or intercept. A plot with pairs()
highly
recommended.
Stan is usually good enough that init values for the chains must not be specified. In extreme cases it is anyway possible to set init values as a list of list.
Value
An object of class bdpreg
which contains out
a stanfit
object returned by rstan::sampling
and standata
as list of input parameters.
References
G. Pioda (2014) https://piodag.github.io/bd1/
Examples
library(rstanbdp)
data(glycHem)
# Bayesian Deming Regression, for example with df=10
fit.1 <-bdpreg(glycHem$Method1,glycHem$Method2,heteroscedastic="homo",
df=10,chain=1,iter=1000)
# Print results
bdpPrint(fit.1,digits_summary = 4)
# Plot 2D intercepts /slopes pairs with CI and MD distance
bdpPlotBE(fit.1,cov.method="MCD",ci=0.95)
# Plot regression with CI
bdpPlot(fit.1,ci=0.95)
# Calculate response, plot histogram and CI
bdpCalcResponse(fit.1,Xval = 6)
# Extract Xhat, Yhat and Residuals
bdpExtract(fit.1)
# Plot a traceplot of the sampled chains
bdpTraceplot(fit.1)
# Plot standardized residuals
bdpPlotResiduals(fit.1)
# Plot posterior samples pairwise
bdpPairs(fit.1)
Mahalanobis distance for the posterior pairs
Description
Mahalanobis distance for the posterior pairs
Usage
bmpMD(stanRegr, cov.method)
Arguments
stanRegr |
Rstan rstanbdp object |
cov.method |
rrcov covariance method ("SDe", "MCD", or "Classical"). Default MCD. |
Value
Chi squared probability of the MD
Method comparison of glycated hemoglobin measurement
Description
This data gives the glycated hemoglobin measured in 20 patients.
Usage
data(glycHem)
Format
A data frame with 20 observations on the following 2 variables.