| Title: | Statistical Tools for Evaluation of in Vitro Diagnostic Reagents |
|---|---|
| Description: | Provides statistical workflows used in the evaluation of in vitro diagnostic reagents. Facilities include method comparison, commutability assessment, Bland-Altman and receiver operating characteristic analysis, qualitative agreement, C5 and C95 estimation, precision and variance-component analysis, linearity, interference, dilution and spiking studies, high-dose hook assessment, measurement uncertainty, reference-material bias, reference intervals, stability studies, quality-control charts, curve fitting, analytical sensitivity, outlier and normality assessment, and sample-size calculations. For methodological details, see Bland and Altman (1986) <doi:10.1016/S0140-6736(86)90837-8>, Passing and Bablok (1983) <doi:10.1515/cclm.1983.21.11.709>, Linnet (1993) <doi:10.1093/clinchem/39.3.424>, Hawkins and Kraker (2026) <doi:10.1093/jalm/jfaf183>, Hanley and McNeil (1982) <doi:10.1148/radiology.143.1.7063747>, Horn et al. (1998) <doi:10.1093/clinchem/44.3.622>, Westgard et al. (1981) <doi:10.1093/clinchem/27.3.493>, and Lu et al. (2016) <doi:10.1515/ijb-2015-0039>. |
| Authors: | hiox-tech [cph, aut, cre] |
| Maintainer: | hiox-tech <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.5 |
| Built: | 2026-09-18 11:50:27 UTC |
| Source: | https://github.com/hiox-tech/ivdtools |
Estimates degradation rates at multiple elevated temperatures, fits the Arrhenius equation, and extrapolates to the target storage temperature to predict shelf life.
arrhenius( data, temperature, time, value, target_temp, order = c("auto", "zero", "first"), direction = c("auto", "decrease", "increase"), limit, bias_type = c("relative", "absolute"), temp_unit = "C", time_unit = "d", conf.level = 0.95 )arrhenius( data, temperature, time, value, target_temp, order = c("auto", "zero", "first"), direction = c("auto", "decrease", "increase"), limit, bias_type = c("relative", "absolute"), temp_unit = "C", time_unit = "d", conf.level = 0.95 )
data |
A data frame. |
temperature |
Column name for storage temperature (numeric). |
time |
Column name for time point (numeric). |
value |
Column name for measurement value (numeric). |
target_temp |
Target storage temperature. |
order |
|
direction |
|
limit |
A positive number for symmetric allowable bias. |
bias_type |
|
temp_unit |
Temperature unit: |
time_unit |
Time unit: m, min, h, d, month, or y. |
conf.level |
Confidence level, default 0.95. |
An S3 object of class "arrhenius".
temp_df <- data.frame(temp = rep(c(25,30,37), each = 3), time = rep(c(0,1,3), 3), val = c(100,98,95, 100,96,90, 100,94,85)) arrhenius(temp_df, "temp", "time", "val", target_temp = 5, limit = 10)temp_df <- data.frame(temp = rep(c(25,30,37), each = 3), time = rep(c(0,1,3), 3), val = c(100,98,95, 100,96,90, 100,94,85)) arrhenius(temp_df, "temp", "time", "val", target_temp = 5, limit = 10)
Compare two ROC curves evaluated on the common complete cases stored in a
single roc() object. A curve can be a marker previously processed by
auc() or a named multivariate model produced by mlr().
## S3 method for class 'roc' auc_compare( x, curves, method = c("ep24", "delong"), conf.level = 0.95, rating_method = c("pearson", "kendall"), name = NULL, ... )## S3 method for class 'roc' auc_compare( x, curves, method = c("ep24", "delong"), conf.level = 0.95, rating_method = c("pearson", "kendall"), name = NULL, ... )
x |
A |
curves |
Character vector naming exactly two marker or MLR curves. The
reported difference is |
method |
Paired comparison method: |
conf.level |
Confidence level for the normal-approximation interval. |
rating_method |
Correlation method for EP24 paired scores: |
name |
Optional unique name for storing the comparison. By default it is generated from the two curve names and method. |
... |
Additional arguments (currently unused). |
method = "ep24" implements the paired Hanley–McNeil approximation in
CLSI EP24-A2. It combines the two single-curve Hanley–McNeil standard
errors with the correlation between the paired AUCs. The latter is obtained
by linear interpolation of EP24-A2 Table 5 from the average within-group
score correlation and average AUC. Coordinates outside the published table
are bounded to its range and recorded in the result.
method = "delong" uses the nonparametric DeLong covariance estimator and
handles ties with half credit. Both methods test the two-sided null
hypothesis that the AUC difference is zero.
The updated roc object, invisibly. The comparison is stored in
x$auc_comparisons[[name]] as a roc_auc_comparison object.
obj <- roc(ivd_roc_example, c("x1", "x2"), "ref") obj <- auc(obj) obj <- auc_compare(obj, c("x1", "x2"), method = "ep24") obj$auc_comparisons[[1L]] obj <- mlr(obj, name = "combined") obj <- auc_compare(obj, c("x1", "combined"), method = "delong")obj <- roc(ivd_roc_example, c("x1", "x2"), "ref") obj <- auc(obj) obj <- auc_compare(obj, c("x1", "x2"), method = "ep24") obj$auc_comparisons[[1L]] obj <- mlr(obj, name = "combined") obj <- auc_compare(obj, c("x1", "combined"), method = "delong")
Compute ROC curves and AUC for each evaluation column.
## S3 method for class 'roc' auc(x, cols = NULL, ...)## S3 method for class 'roc' auc(x, cols = NULL, ...)
x |
roc object |
cols |
column names to analyze; default is all |
... |
reserved arguments |
Updated roc object with results stored in $auc_list and $auc_table
obj <- roc(ivd_roc_example, cols = c("x1", "x2"), reference = "ref") obj <- auc(obj) obj <- auc(obj, cols = "x1")obj <- roc(ivd_roc_example, cols = c("x1", "x2"), reference = "ref") obj <- auc(obj) obj <- auc(obj, cols = "x1")
Compute bias at specified medical decision levels (MDL) based on stored regression results: bias = predicted_candidate - reference = (intercept + slope * x0) - x0 = intercept + (slope - 1) * x0
## S3 method for class 'mcr' bias( x, mdl, level = 0.95, interval = c("", "confidence", "prediction", "both"), ci_method = c("auto", "analytic", "jackknife", "rank", "bootstrap_percentile", "bootstrap_standard"), bootstrap_replicates = 5000L, seed = NULL, ... )## S3 method for class 'mcr' bias( x, mdl, level = 0.95, interval = c("", "confidence", "prediction", "both"), ci_method = c("auto", "analytic", "jackknife", "rank", "bootstrap_percentile", "bootstrap_standard"), bootstrap_replicates = 5000L, seed = NULL, ... )
x |
mcr object (must call regression() first) |
mdl |
Medical decision levels (numeric vector) on the reference/X scale |
level |
Confidence level, default 0.95 |
interval |
Interval type: "" (point estimate, default), "confidence" (confidence interval), "prediction" (prediction interval), "both" (confidence + prediction) |
ci_method |
Parameter-uncertainty method. |
bootstrap_replicates |
Number of paired Bootstrap resamples; at least 5000 when a Bootstrap method is used. |
seed |
Optional integer seed. |
... |
Additional arguments (currently unused). |
Bias follows the conventional candidate-minus-reference direction; a positive value indicates that the candidate method is higher.
Updated mcr object (invisible), results stored in $bias
obj <- mcr(ivd_mcr_example, "sid", "test", "ref") obj <- regression(obj, method = "ols") bias(obj, mdl = c(200, 400, 600)) bias(obj, mdl = c(200, 400, 600), interval = "both")obj <- mcr(ivd_mcr_example, "sid", "test", "ref") obj <- regression(obj, method = "ols") bias(obj, mdl = c(200, 400, 600)) bias(obj, mdl = c(200, 400, 600), interval = "both")
Calculate Limits of Agreement between two measurement methods, supporting three y-axis metrics: difference, ratio, and percent difference.
## S3 method for class 'mcr' bland_altman( x, type = c("difference", "ratio", "percent"), x_axis = c("mean", "candidate", "reference"), percent_denominator = c("reference", "mean", "candidate"), agree.level = 0.95, conf.level = 0.95, method = c("parametric", "nonparametric", "hodges_lehmann"), median_ci_method = c("order_statistic", "interpolated"), bootstrap_replicates = 5000L, seed = NULL, ... )## S3 method for class 'mcr' bland_altman( x, type = c("difference", "ratio", "percent"), x_axis = c("mean", "candidate", "reference"), percent_denominator = c("reference", "mean", "candidate"), agree.level = 0.95, conf.level = 0.95, method = c("parametric", "nonparametric", "hodges_lehmann"), median_ci_method = c("order_statistic", "interpolated"), bootstrap_replicates = 5000L, seed = NULL, ... )
x |
mcr object |
type |
Y-axis metric: "difference" (default), "ratio" or "percent" |
x_axis |
X-axis: "mean" (average of the two methods, default), "candidate" (test method values), "reference" (reference method values) |
percent_denominator |
Denominator used when |
agree.level |
Agreement level for limits of agreement, default 0.95 (i.e., 95% LoA) |
conf.level |
Confidence level for LoA confidence intervals, default 0.95 |
method |
Estimation method: "parametric" uses the mean, its t confidence interval, the standard deviation, and parametric limits of agreement; "nonparametric" uses the median, an exact sign-test order-statistic interval, empirical limits, and percentile Bootstrap confidence intervals for the limits. "hodges_lehmann" uses the Walsh-average pseudomedian and an uncorrected Wilcoxon/Tukey interval; its LoA remain empirical quantiles with percentile Bootstrap intervals. |
median_ci_method |
For the ordinary nonparametric median, either the conservative order-statistic interval (default) or the EP09c continuous-rank normal approximation with linear interpolation between adjacent order statistics. |
bootstrap_replicates |
Number of Bootstrap resamples for the nonparametric method, default 5000. Must be at least 100. |
seed |
Optional integer random seed for reproducible Bootstrap intervals. |
... |
Additional arguments |
Updated mcr object (invisible), with results stored in $bland_altman.
The result records the selected method, its centre estimate and
center_ci. Method-specific aliases are mean_diff_ci for the
parametric mean and median_diff_ci for the nonparametric median.
The original mean_diff and sd_diff fields are retained for
compatibility.
obj <- mcr(ivd_mcr_example, "sid", "test", "ref") bland_altman(obj) bland_altman(obj, type = "ratio") bland_altman(obj, type = "percent", x_axis = "reference") bland_altman(obj, type = "percent", x_axis = "mean", percent_denominator = "mean")obj <- mcr(ivd_mcr_example, "sid", "test", "ref") bland_altman(obj) bland_altman(obj, type = "ratio") bland_altman(obj, type = "percent", x_axis = "reference") bland_altman(obj, type = "percent", x_axis = "mean", percent_denominator = "mean")
Create a bottle/batch ANOVA analysis object. Supports one-way and nested designs, with automatic assumption checks, missing value reporting, and ANOVA table output.
bottle_anova(data, formula, conf.level = 0.95)bottle_anova(data, formula, conf.level = 0.95)
data |
A data frame |
formula |
A formula, e.g. |
conf.level |
Confidence level (default 0.95) |
An S3 object of class "bottle_anova" with components:
call |
Function call |
data |
Original data |
formula |
Input formula |
conf.level |
Confidence level |
response_name |
Response variable name |
design_type |
Design type ( |
rhs_vars |
Right-hand side grouping variable names |
term_labels |
Model term labels |
n_total |
Total sample size |
n_complete |
Number of complete cases |
missing_rows |
Indices of excluded missing rows |
cc_data |
Complete-case data frame |
aov_fit |
|
aov_table |
ANOVA table |
desc_stats |
Descriptive statistics table |
desc_group_col |
Grouping column label |
assumptions |
Assumption test results (Bartlett + Shapiro-Wilk) |
group_means |
Group means |
tukey_results |
Tukey HSD results (NULL initially, filled by |
# One-way design df1 <- data.frame( bottle = rep(c("A", "B", "C"), each = 5), value = c(rnorm(5, 10, 1), rnorm(5, 12, 1), rnorm(5, 11, 1)) ) obj <- bottle_anova(df1, value ~ bottle) # Nested design df2 <- data.frame( lot = rep(c("L1", "L2"), each = 10), vial = rep(c("V1", "V2"), each = 5, times = 2), value = c(rnorm(5, 10, 1), rnorm(5, 10.5, 1), rnorm(5, 12, 1), rnorm(5, 12.5, 1)) ) obj2 <- bottle_anova(df2, value ~ lot/vial)# One-way design df1 <- data.frame( bottle = rep(c("A", "B", "C"), each = 5), value = c(rnorm(5, 10, 1), rnorm(5, 12, 1), rnorm(5, 11, 1)) ) obj <- bottle_anova(df1, value ~ bottle) # Nested design df2 <- data.frame( lot = rep(c("L1", "L2"), each = 10), vial = rep(c("V1", "V2"), each = 5, times = 2), value = c(rnorm(5, 10, 1), rnorm(5, 10.5, 1), rnorm(5, 12, 1), rnorm(5, 12.5, 1)) ) obj2 <- bottle_anova(df2, value ~ lot/vial)
Estimates response values associated with selected probabilities of a
qualitative result. The response SD is modeled as a function of the expected
response using a VFP precision profile. For direction = "geq", the event
is result >= cutoff; for direction = "leq", the event is
result <= cutoff. No acceptance decision is made.
c5_c95( data, result = NULL, sample = NULL, cutoff, direction = c("geq", "leq"), probabilities = c(0.05, 0.95), component = NULL, model.no = 1:10, K = 2, search_range = NULL, tol = 1e-07 )c5_c95( data, result = NULL, sample = NULL, cutoff, direction = c("geq", "leq"), probabilities = c(0.05, 0.95), component = NULL, model.no = 1:10, K = 2, search_range = NULL, tol = 1e-07 )
data |
A data frame of replicate continuous responses, or a
|
result |
Name of the numeric response column. Required for a data frame. |
sample |
Name of the sample or level column. Required for a data frame. |
cutoff |
One or more finite decision cutoffs. |
direction |
Direction defining the condition of interest: |
probabilities |
Probabilities to estimate, default |
component |
Precision-profile component used when |
model.no |
Candidate VFP model numbers for raw data. |
K |
Fixed exponent supplied to applicable VFP models. |
search_range |
Optional two-element finite numeric range for root finding. By default, the observed mean range is expanded automatically. |
tol |
Positive numeric root-finding tolerance. |
An object of class c5_c95. Its estimates element contains
the estimated response, fitted SD, achieved probability, extrapolation flag,
and root-search diagnostics for each cutoff and probability.
set.seed(1203) cx_data <- data.frame( level = rep(paste0("L", 1:7), each = 20), response = unlist(lapply(seq(34, 46, length.out = 7), function(mu) stats::rnorm(20, mean = mu, sd = 0.7 + 0.01 * mu))) ) cx <- c5_c95(cx_data, result = "response", sample = "level", cutoff = 40, model.no = 1) cx$estimates plot(cx)set.seed(1203) cx_data <- data.frame( level = rep(paste0("L", 1:7), each = 20), response = unlist(lapply(seq(34, 46, length.out = 7), function(mu) stats::rnorm(20, mean = mu, sd = 0.7 + 0.01 * mu))) ) cx <- c5_c95(cx_data, result = "response", sample = "level", cutoff = 40, model.no = 1) cx$estimates plot(cx)
Compute confidence intervals for each variance component (SD and %CV) based on
Satterthwaite approximation. Requires variance() to be run first to populate
the $results slot.
## S3 method for class 'precision' ci(x, digits = 4, ...)## S3 method for class 'precision' ci(x, digits = 4, ...)
x |
|
digits |
Number of decimal places, default |
... |
Reserved arguments |
This method reports intervals for the fitted model components and
the total component. EP05 semantic combinations such as multisite
within-laboratory precision require the day, run, and site mapping
supplied to report.precision and are therefore constructed
by report(x, ..., table = "CI").
Updated precision object with results stored in $ci
data(VCAdata1, package = "VCA") obj <- precision(VCAdata1, y ~ day/run, by = "sample") obj <- variance(obj) obj <- ci(obj)data(VCAdata1, package = "VCA") obj <- precision(VCAdata1, y ~ day/run, by = "sample") obj <- variance(obj) obj <- ci(obj)
Extract coefficients from an equation fit
## S3 method for class 'fit_equation' coef(object, ...)## S3 method for class 'fit_equation' coef(object, ...)
object |
A |
... |
Additional arguments (currently unused). |
A named numeric vector of model coefficients.
df <- data.frame(x = 1:5, y = c(2.1, 4.0, 6.2, 7.9, 10.1)) f <- fit_equation("E01", df, "x", "y") coef(f)df <- data.frame(x = 1:5, y = c(2.1, 4.0, 6.2, 7.9, 10.1)) f <- fit_equation("E01", df, "x", "y") coef(f)
Implements the statistical calculations for CLSI EP14-A3 Deming-regression prediction intervals, CLSI EP30-A prediction intervals and relative residuals, the IFCC Part 2 difference-in-bias approach, or the IFCC Part 3 calibration-effectiveness approach. The function expects long-format data and does not assess specimen collection, run randomization, reagent lots, or other experimental conduct.
commutability( data, sample_id, material_type = NULL, procedure, result, position = NULL, approach = c("ep14", "ep30", "ifcc", "calibration"), scale = c("raw", "log10", "ln"), reference_procedure = NULL, procedure_pairs = NULL, conf.level = 0.95, criterion = NULL, bias_model = c("constant_global", "constant_local", "linear_local"), local_n = NULL, coverage_factor = 1.9, rm_position = c("pooled", "material_specific"), rm_set_size = 1L, relative_residual_limit = 2, calibration_stage = NULL, calibration_replicate_summary = c("mean", "median", "error"), exclude_procedures = NULL, w3_reference_procedure = NULL, material_type_map = NULL )commutability( data, sample_id, material_type = NULL, procedure, result, position = NULL, approach = c("ep14", "ep30", "ifcc", "calibration"), scale = c("raw", "log10", "ln"), reference_procedure = NULL, procedure_pairs = NULL, conf.level = 0.95, criterion = NULL, bias_model = c("constant_global", "constant_local", "linear_local"), local_n = NULL, coverage_factor = 1.9, rm_position = c("pooled", "material_specific"), rm_set_size = 1L, relative_residual_limit = 2, calibration_stage = NULL, calibration_replicate_summary = c("mean", "median", "error"), exclude_procedures = NULL, w3_reference_procedure = NULL, material_type_map = NULL )
data |
A data frame in long format. |
sample_id, material_type, procedure, result
|
Column names identifying the
material, material type, measurement procedure, and numeric result.
|
position |
Optional column identifying RM positions within a run;
required for |
approach |
One of |
scale |
Analysis scale: |
reference_procedure |
Optional reference measurement procedure. When supplied, it is compared with every other procedure. |
procedure_pairs |
Optional list of two-element procedure vectors. |
conf.level |
Prediction-interval level for EP14 and EP30. |
criterion |
Predefined IFCC Part 2 criterion on the selected analysis scale, or maximum IMPBR percentage for calibration effectiveness. It is mandatory for the two IFCC-derived approaches and is never estimated from data. |
bias_model |
IFCC clinical-sample bias model: |
local_n |
Number of clinical samples around each RM for a local IFCC model. Ignored for a global model. |
coverage_factor |
IFCC uncertainty coverage factor; default 1.9. |
rm_position |
IFCC position-mean uncertainty mode. |
rm_set_size |
Number of related reference materials used as a set for the EP30 normal critical-value adjustment. Independent materials use 1. |
relative_residual_limit |
Positive EP30 relative-residual limit; default 2. |
calibration_stage |
Column identifying |
calibration_replicate_summary |
How multiple calibration results in the
same sample, procedure, and stage are reduced to one reported result:
|
exclude_procedures |
Optional procedures explicitly excluded after investigation in a calibration-effectiveness analysis. Full-set results are retained. |
w3_reference_procedure |
Procedure whose SD/W(3) ratio scales the robust
W(3) statistics. The first observed procedure is used when |
material_type_map |
Optional named character vector that explicitly maps
observed material-type values to |
Sample-size, replicate-count, position-matching, and method-count targets
from CLSI and IFCC publications are reported in design_checks; they are not
treated as proof of compliance and do not stop a calculation that is
statistically defined. Conditions required by the formula itself still
produce an error. A local result that cannot be calculated is returned as
not_evaluable, while an unavailable secondary statistic is returned as
NA.
An object of class commutability_result containing material-level
results, model estimates, design checks, IFCC position diagnostics, and
the transformed analysis data. Design checks report whether the supplied
study meets the sample-size and replication recommendations of the named
method; unmet checks do not prevent otherwise computable analyses.
# Long-format replicate results for eight clinical samples. clinical <- expand.grid( sample = paste0("CS", 1:8), procedure = c("MP1", "MP2"), replicate = 1:3, stringsAsFactors = FALSE ) level <- setNames(seq(10, 80, length.out = 8), paste0("CS", 1:8)) clinical$result <- level[clinical$sample] + ifelse(clinical$procedure == "MP2", 1, 0) + rep(c(-0.2, 0, 0.2), each = 16) clinical$material_type <- "clinical" clinical$position <- NA_integer_ # One reference material measured at three positions, in triplicate. rm <- expand.grid( sample = "RM1", procedure = c("MP1", "MP2"), position = 1:3, replicate = 1:3, stringsAsFactors = FALSE ) rm$result <- 45 + ifelse(rm$procedure == "MP2", 1, 0) + rep(c(-0.1, 0, 0.1), each = 6) rm$material_type <- "rm" columns <- c("sample", "material_type", "procedure", "result", "position", "replicate") example_data <- rbind(clinical[columns], rm[columns]) ep14 <- commutability( example_data, "sample", "material_type", "procedure", "result", approach = "ep14" ) ep14$results # Explicitly map nonstandard material-type labels. mapped_data <- example_data mapped_data$material_type <- ifelse( mapped_data$material_type == "clinical", "patient_sample", "candidate_rm" ) ep14_mapped <- commutability( mapped_data, "sample", "material_type", "procedure", "result", approach = "ep14", material_type_map = c(patient_sample = "clinical", candidate_rm = "rm") ) ep14_mapped$results ifcc <- commutability( example_data, "sample", "material_type", "procedure", "result", position = "position", approach = "ifcc", criterion = 2, bias_model = "constant_global" ) ifcc$results# Long-format replicate results for eight clinical samples. clinical <- expand.grid( sample = paste0("CS", 1:8), procedure = c("MP1", "MP2"), replicate = 1:3, stringsAsFactors = FALSE ) level <- setNames(seq(10, 80, length.out = 8), paste0("CS", 1:8)) clinical$result <- level[clinical$sample] + ifelse(clinical$procedure == "MP2", 1, 0) + rep(c(-0.2, 0, 0.2), each = 16) clinical$material_type <- "clinical" clinical$position <- NA_integer_ # One reference material measured at three positions, in triplicate. rm <- expand.grid( sample = "RM1", procedure = c("MP1", "MP2"), position = 1:3, replicate = 1:3, stringsAsFactors = FALSE ) rm$result <- 45 + ifelse(rm$procedure == "MP2", 1, 0) + rep(c(-0.1, 0, 0.1), each = 6) rm$material_type <- "rm" columns <- c("sample", "material_type", "procedure", "result", "position", "replicate") example_data <- rbind(clinical[columns], rm[columns]) ep14 <- commutability( example_data, "sample", "material_type", "procedure", "result", approach = "ep14" ) ep14$results # Explicitly map nonstandard material-type labels. mapped_data <- example_data mapped_data$material_type <- ifelse( mapped_data$material_type == "clinical", "patient_sample", "candidate_rm" ) ep14_mapped <- commutability( mapped_data, "sample", "material_type", "procedure", "result", approach = "ep14", material_type_map = c(patient_sample = "clinical", candidate_rm = "rm") ) ep14_mapped$results ifcc <- commutability( example_data, "sample", "material_type", "procedure", "result", position = "position", approach = "ifcc", criterion = 2, bias_model = "constant_global" ) ifcc$results
Fit and compare multiple equations
compare_equation(data, x = "x", y = "y", eqs = NULL, ...)compare_equation(data, x = "x", y = "y", eqs = NULL, ...)
data |
a data frame |
x |
x column name |
y |
y column name |
eqs |
equation name/ID vector; NULL = all Response equations |
... |
additional arguments passed to fit_equation |
An object of class "compare_equation" with components:
table |
data.frame sorted by AIC: Eq, Name, Formula, nPar, AIC, deltaAIC, R2, RSE |
fits |
list of fit_equation objects, named by eq_id |
failed |
character vector of eq IDs that failed to fit |
data, x, y
|
input data reference |
df <- data.frame( x = c(0.1, 0.3, 1, 3, 10, 30, 100), y = c(12, 25, 48, 72, 88, 96, 99) ) compare_equation(df, "x", "y", eqs = c("E01", "E06", "E07"))df <- data.frame( x = c(0.1, 0.3, 1, 3, 10, 30, 100), y = c(12, 25, 48, 72, 88, 96, 99) ) compare_equation(df, "x", "y", eqs = c("E01", "E06", "E07"))
Creates new binary columns (0/1) from existing quantitative columns using
specified cutoff values, appending them to the original data frame.
New columns are named <col>_binary.
continuous_to_binary(data, cols, cutoff)continuous_to_binary(data, cols, cutoff)
data |
data frame |
cols |
character vector of column names to binarize |
cutoff |
numeric vector of cutoff values; recycled to |
data frame with original columns plus new <col>_binary columns
df <- data.frame(x = 1:10, y = rnorm(10)) continuous_to_binary(df, "x", 5) continuous_to_binary(df, c("x", "y"), c(5, 0))df <- data.frame(x = 1:10, y = rnorm(10)) continuous_to_binary(df, "x", 5) continuous_to_binary(df, c("x", "y"), c(5, 0))
Perform correlation analysis between the reference method (X) and candidate method (Y), supporting Pearson, Spearman, and Kendall methods.
## S3 method for class 'mcr' correlation(x, method = c("pearson", "spearman", "kendall"), ...)## S3 method for class 'mcr' correlation(x, method = c("pearson", "spearman", "kendall"), ...)
x |
mcr object |
method |
Correlation method: "pearson" (default), "spearman", or "kendall" |
... |
Additional arguments passed to cor.test |
Updated mcr object (invisible), results stored in $correlation
obj <- mcr(ivd_mcr_example, "sid", "test", "ref") correlation(obj) correlation(obj, method = "spearman")obj <- mcr(ivd_mcr_example, "sid", "test", "ref") correlation(obj) correlation(obj, method = "spearman")
When raw data are not available and only the four diagnostic test frequencies are known, use this function to directly construct a result object with the same structure as raw_to_table(), compatible with print() for displaying the fourfold table.
counts_to_table( tp, fp, tn, fn, candidate = "candidate", reference = "reference", candidate_levels = c("positive", "negative"), reference_levels = c("positive", "negative") )counts_to_table( tp, fp, tn, fn, candidate = "candidate", reference = "reference", candidate_levels = c("positive", "negative"), reference_levels = c("positive", "negative") )
tp |
True positives (candidate=level1, reference=level1) |
fp |
False positives (candidate=level1, reference=level2) |
tn |
True negatives (candidate=level2, reference=level2) |
fn |
False negatives (candidate=level2, reference=level1) |
candidate |
Candidate method name (character) |
reference |
Reference method name (character) |
candidate_levels |
Two levels of the candidate method, default c("positive", "negative") |
reference_levels |
Two levels of the reference method, default c("positive", "negative") |
A fourfold_table object (S3 class "fourfold_table") with the same structure as raw_to_table(): - $freq_raw Long-format frequency data.frame - $table 3x3 matrix with margins - $n Total sample size - $print Print slot - $candidate_levels Levels of the candidate method - $reference_levels Levels of the reference method Use print() directly to display the fourfold table.
result <- counts_to_table(tp = 45, fp = 12, tn = 80, fn = 5, candidate = "new method", reference = "gold standard")result <- counts_to_table(tp = 45, fp = 12, tn = 80, fn = 5, candidate = "new method", reference = "gold standard")
For each evaluation column, compute diagnostic metrics at all cutoff values, and identify the optimal cutoff (maximum Youden index, closest to (0,1) corner).
## S3 method for class 'roc' cutoff(x, cols = NULL, ...)## S3 method for class 'roc' cutoff(x, cols = NULL, ...)
x |
roc object |
cols |
column names to analyze; default is all |
... |
reserved arguments |
Updated roc object with results stored in $cutoff_table
obj <- roc(ivd_roc_example, cols = c("x1", "x2"), reference = "ref") obj <- auc(obj) cutoff(obj) cutoff(obj, cols = "x1")obj <- roc(ivd_roc_example, cols = c("x1", "x2"), reference = "ref") obj <- auc(obj) cutoff(obj) cutoff(obj, cols = "x1")
Describe an analysis object
describe(x, ...) correlation(x, ...) regression(x, ...) bias(x, ...) bland_altman(x, ...) report(x, ...) profile(object, ...) normal(x, ...) ci(x, ...) variance(x, ...) vc(x, ...) diagnostics(object, ...) kappa(x, ...) mcnemar(x, ...) cutoff(x, ...) mlr(x, ...) auc(x, ...) auc_compare(x, ...) tukey(x, ...)describe(x, ...) correlation(x, ...) regression(x, ...) bias(x, ...) bland_altman(x, ...) report(x, ...) profile(object, ...) normal(x, ...) ci(x, ...) variance(x, ...) vc(x, ...) diagnostics(object, ...) kappa(x, ...) mcnemar(x, ...) cutoff(x, ...) mlr(x, ...) auc(x, ...) auc_compare(x, ...) tukey(x, ...)
x |
An S3 analysis object. |
... |
Additional arguments passed to a method. |
object |
An S3 analysis object. |
The value returned by the dispatched method.
The value returned by the dispatched method.
The value returned by the dispatched method.
The value returned by the dispatched method.
The value returned by the dispatched method.
The value returned by the dispatched method.
The value returned by the dispatched method.
The value returned by the dispatched method.
The value returned by the dispatched method.
The value returned by the dispatched method.
The value returned by the dispatched method.
The value returned by the dispatched method.
The value returned by the dispatched method.
The value returned by the dispatched method.
The value returned by the dispatched method.
The value returned by the dispatched method.
The value returned by the dispatched method.
The value returned by the dispatched method.
The value returned by the dispatched method.
obj <- mcr(ivd_mcr_example, "sid", "test", "ref") describe(obj)obj <- mcr(ivd_mcr_example, "sid", "test", "ref") describe(obj)
Print variable description information for a fourfold_table object (from raw_to_table). If the object comes from counts_to_table (no raw data), indicates unavailability.
## S3 method for class 'fourfold_table' describe(x, ...)## S3 method for class 'fourfold_table' describe(x, ...)
x |
a fourfold_table object |
... |
reserved arguments |
Updated fourfold_table object, with $describe slot filled with description results
df <- data.frame( new = c("positive","positive","negative","negative","positive","negative"), gold = c("positive","negative","positive","negative","positive","positive"), age = c(45, 52, 38, 61, 47, 55), gender = c("M","F","F","M","M","F"), id = c("S001","S002","S003","S004","S005","S006") ) tab <- raw_to_table(df, "new", "gold", id = "id") tab <- describe(tab)df <- data.frame( new = c("positive","positive","negative","negative","positive","negative"), gold = c("positive","negative","positive","negative","positive","positive"), age = c(45, 52, 38, 61, 47, 55), gender = c("M","F","F","M","M","F"), id = c("S001","S002","S003","S004","S005","S006") ) tab <- raw_to_table(df, "new", "gold", id = "id") tab <- describe(tab)
Computes data overview (rows/columns/ID duplicates), per-column summaries,
and a side-by-side comparison table of candidate, reference, and Diff.
Results are stored in x$describe (class mcr_describe) and
displayed via print.mcr_describe() (e.g., when calling summary()).
## S3 method for class 'mcr' describe(x, cols = NULL, digits = 4L, ...)## S3 method for class 'mcr' describe(x, cols = NULL, digits = 4L, ...)
x |
mcr object |
cols |
Column name vector to analyze; by default, analyzes all columns except
id, candidate, and reference. Supports exclusion with |
digits |
Number of decimal places, default 4 |
... |
Additional arguments |
Updated mcr object (invisible), results stored in x$describe
obj <- mcr(ivd_mcr_example, "sid", "test", "ref") describe(obj)obj <- mcr(ivd_mcr_example, "sid", "test", "ref") describe(obj)
Print distribution summaries for evaluation columns and the reference column (if numeric). When the reference is binary, evaluation column distributions are shown grouped by positive/negative.
## S3 method for class 'roc' describe(x, cols = NULL, digits = 4L, ...)## S3 method for class 'roc' describe(x, cols = NULL, digits = 4L, ...)
x |
roc object |
cols |
columns to describe; defaults to all evaluation columns + reference column (if numeric) |
digits |
number of decimal places, default 4 |
... |
reserved arguments |
Updated roc object with results stored in $describe
obj <- roc(ivd_roc_example, cols = "x1", reference = "ref") describe(obj)obj <- roc(ivd_roc_example, cols = "x1", reference = "ref") describe(obj)
Diagnostic performance metrics: calculate sensitivity, specificity, likelihood ratios, etc. with confidence intervals for a fourfold_table
## S3 method for class 'fourfold_table' diagnostics( object, conf.level = 0.95, ci.method = "wilson", prevalence = NULL, ... )## S3 method for class 'fourfold_table' diagnostics( object, conf.level = 0.95, ci.method = "wilson", prevalence = NULL, ... )
object |
a fourfold_table object |
conf.level |
Confidence level, default 0.95 |
ci.method |
Proportion confidence interval method, default "wilson". Supports "wald", "wald-cc", "wilson", "wilson-cc", "agresti-coull", "jeffreys", "clopper-pearson" |
prevalence |
User-specified prevalence. If provided, PPV/NPV will be calculated based on this prevalence via Bayes' theorem (rather than the observed prevalence in the data). |
... |
Additional arguments passed to print |
Updated fourfold_table object, with diagnostic performance metrics stored in $diagnostics: - $tp / $fp / $fn / $tn / $n Four-fold frequencies and total sample size - $sensitivity Sensitivity with CI - $specificity Specificity with CI - $ppv Positive predictive value with CI - $npv Negative predictive value with CI - $accuracy Accuracy with CI - $prevalence Prevalence with CI - $lr_positive Positive likelihood ratio with CI - $lr_negative Negative likelihood ratio with CI - $odds_ratio Odds ratio with CI - $conf_level Confidence level used - $ci_method Method name used - $prev_specified Whether user specified prevalence
tab <- raw_to_table(ivd_qualitative_example, "new", "gold", positive = "positive", id = "id") tab <- diagnostics(tab) tab <- diagnostics(tab, prevalence = 0.3) tab <- diagnostics(tab, conf.level = 0.90) tab <- diagnostics(tab, ci.method = "clopper-pearson")tab <- raw_to_table(ivd_qualitative_example, "new", "gold", positive = "positive", id = "id") tab <- diagnostics(tab) tab <- diagnostics(tab, prevalence = 0.3) tab <- diagnostics(tab, conf.level = 0.90) tab <- diagnostics(tab, ci.method = "clopper-pearson")
Summarizes replicate measurements and calculates target concentration, dilution-corrected concentration, and recovery for each specimen and dilution factor. Across-specimen mean recovery and its Student t confidence interval are calculated for every dilution factor. No acceptance criterion or suitability decision is applied.
dilution_recovery( data, sample, result, dilution_factor, assigned = NULL, diluent_value = 0, conf.level = 0.95 )dilution_recovery( data, sample, result, dilution_factor, assigned = NULL, diluent_value = 0, conf.level = 0.95 )
data |
Data frame in long format, with one row per measurement. |
sample |
Sample-identification column. |
result |
Numeric measurement-result column. |
dilution_factor |
Numeric dilution-factor column. Undiluted material is represented by 1, a 1/2 dilution by 2, and a 1/20 dilution by 20. |
assigned |
Optional column containing one assigned original-sample concentration per sample. When omitted, the mean undiluted result is used. |
diluent_value |
Measurand concentration in the diluent. The default is 0. |
conf.level |
Confidence level for the across-sample mean recovery. |
An object of class dilution_recovery containing results,
summary, the retained data, and excluded row indices.
CLSI. Establishing and Verifying an Extended Measuring Interval Through Specimen Dilution and Spiking. EP34, 1st ed. 2018.
dilution_data <- data.frame( sample = rep(c("S1", "S2"), each = 6), factor = rep(rep(c(1, 2, 4), each = 2), 2), result = c(99, 101, 49, 51, 24, 26, 199, 201, 99, 101, 49, 51) ) dilution <- dilution_recovery( dilution_data, "sample", "result", "factor" ) dilution$summarydilution_data <- data.frame( sample = rep(c("S1", "S2"), each = 6), factor = rep(rep(c(1, 2, 4), each = 2), 2), result = c(99, 101, 49, 51, 24, 26, 199, 201, 99, 101, 49, 51) ) dilution <- dilution_recovery( dilution_data, "sample", "result", "factor" ) dilution$summary
General-purpose equation fitting
fit_equation( eq, data, x = "x", y = "y", start = NULL, lower = NULL, upper = NULL, constraints = NULL, weights = NULL, ... )fit_equation( eq, data, x = "x", y = "y", start = NULL, lower = NULL, upper = NULL, constraints = NULL, weights = NULL, ... )
eq |
equation identifier: ID("E07"), name("4PLC"), or a custom formula string ("y ~ aexp(-bx)") |
data |
a data frame |
x |
x variable column name (default "x") |
y |
y variable column name (default "y") |
start |
named list of starting values (NULL=auto) |
lower |
named list/vector of lower bounds (e.g. list(Vmax=0, Km=0)) |
upper |
named list/vector of upper bounds |
constraints |
list of constraint functions: list(ineq = f, eq = g) f(par) returns a vector; all values must be non-positive g(par) returns a vector; must satisfy all(g(par) = 0) |
weights |
weights: NULL(equal) / numeric vector / method name string methods: "equal", "1/y", "1/y^2", "1/x", "1/x^2" |
... |
additional arguments passed to nlsLM() / nloptr() |
an S3 object of class "fit_equation"
# ==== Response curve fitting ==== # 1) Linear df <- data.frame(x = 1:5, y = c(2.1, 4.0, 6.2, 7.9, 10.1)) f1 <- fit_equation("E01", df, "x", "y") print(f1) # 2) Logarithmic f2 <- fit_equation("E06", df, "x", "y") print(f2) # 3) 4PLC (dose-response, descending) df4plc <- data.frame( conc = c(0.1, 0.3, 1, 3, 10, 30, 100), resp = c(99, 96, 88, 72, 48, 25, 12) ) f3 <- fit_equation("E07", df4plc, "conc", "resp") print(f3) # 4) Custom formula f4 <- fit_equation("a + b * log(x)", df4plc, "conc", "resp") print(f4) # 5) Box constraints (parameter bounds) f5 <- fit_equation("E07", df4plc, "conc", "resp", lower = list(D = 0), upper = list(D = 5)) print(f5) # 6) Inequality constraints (parameter relationship) # require D > 1 (Hill slope cannot be too shallow) f6 <- fit_equation("E07", df4plc, "conc", "resp", constraints = list(ineq = function(p) 1 - p["D"])) print(f6) # 7) Equality constraints (fixed parameter relationship) # fix b = 0.5 in exponential decay y = a*exp(-b*x) df_exp <- data.frame(x = 0:5, y = c(10, 6.1, 3.7, 2.2, 1.4, 0.8)) f7 <- fit_equation("E04", df_exp, "x", "y", constraints = list(eq = function(p) p["b"] - 0.5)) print(f7) # 8) Weighted fitting via replicate_to_mean # data with replicate measurements (8 dose levels, 3 replicates each) df_rep <- data.frame( dose = rep(c(0.3, 0.6, 1.5, 4, 10, 25, 60, 150), each = 3), resp = c(4.1, 3.8, 3.9, 8.5, 8.9, 8.6, 18.2, 17.9, 18.5, 34.6, 35.1, 34.8, 54.3, 53.9, 54.7, 73.0, 73.6, 73.2, 87.5, 87.1, 87.8, 97.9, 98.3, 98.0) ) # first summarize, generate inverse-variance weights rep <- replicate_to_mean(df_rep, "dose", "resp", weights = "1/sd^2") # fit 4PLC with summarized means and explicit start values f8 <- fit_equation("E07", rep, x = "x", y = "y_mean", weights = rep$weight, start = list(A = 2, B = 100, C = 8, D = -1.5)) print(f8)# ==== Response curve fitting ==== # 1) Linear df <- data.frame(x = 1:5, y = c(2.1, 4.0, 6.2, 7.9, 10.1)) f1 <- fit_equation("E01", df, "x", "y") print(f1) # 2) Logarithmic f2 <- fit_equation("E06", df, "x", "y") print(f2) # 3) 4PLC (dose-response, descending) df4plc <- data.frame( conc = c(0.1, 0.3, 1, 3, 10, 30, 100), resp = c(99, 96, 88, 72, 48, 25, 12) ) f3 <- fit_equation("E07", df4plc, "conc", "resp") print(f3) # 4) Custom formula f4 <- fit_equation("a + b * log(x)", df4plc, "conc", "resp") print(f4) # 5) Box constraints (parameter bounds) f5 <- fit_equation("E07", df4plc, "conc", "resp", lower = list(D = 0), upper = list(D = 5)) print(f5) # 6) Inequality constraints (parameter relationship) # require D > 1 (Hill slope cannot be too shallow) f6 <- fit_equation("E07", df4plc, "conc", "resp", constraints = list(ineq = function(p) 1 - p["D"])) print(f6) # 7) Equality constraints (fixed parameter relationship) # fix b = 0.5 in exponential decay y = a*exp(-b*x) df_exp <- data.frame(x = 0:5, y = c(10, 6.1, 3.7, 2.2, 1.4, 0.8)) f7 <- fit_equation("E04", df_exp, "x", "y", constraints = list(eq = function(p) p["b"] - 0.5)) print(f7) # 8) Weighted fitting via replicate_to_mean # data with replicate measurements (8 dose levels, 3 replicates each) df_rep <- data.frame( dose = rep(c(0.3, 0.6, 1.5, 4, 10, 25, 60, 150), each = 3), resp = c(4.1, 3.8, 3.9, 8.5, 8.9, 8.6, 18.2, 17.9, 18.5, 34.6, 35.1, 34.8, 54.3, 53.9, 54.7, 73.0, 73.6, 73.2, 87.5, 87.1, 87.8, 97.9, 98.3, 98.0) ) # first summarize, generate inverse-variance weights rep <- replicate_to_mean(df_rep, "dose", "resp", weights = "1/sd^2") # fit 4PLC with summarized means and explicit start values f8 <- fit_equation("E07", rep, x = "x", y = "y_mean", weights = rep$weight, start = list(A = 2, B = 100, C = 8, D = -1.5)) print(f8)
Summarizes raw response by known concentration and identifies the first
post-peak measured concentration whose mean response is at or below the raw
response associated with the ULoQ. The reported hook_concentration is the
immediately preceding measured concentration; no interpolation is used. No
hook-effect or extended-interval acceptability decision is made.
hook_effect( data, concentration, response, series = NULL, uloq, uloq_response = NULL, conf.level = 0.95 )hook_effect( data, concentration, response, series = NULL, uloq, uloq_response = NULL, conf.level = 0.95 )
data |
Data frame containing known concentrations and raw responses. |
concentration |
Numeric known-concentration column. |
response |
Numeric raw-response column. |
series |
Optional column identifying independent hook experiments. |
uloq |
Finite concentration representing the upper limit of quantitation. |
uloq_response |
Optional raw response at the ULoQ. It may be one finite
value for all series or one value per series. When omitted, each series
must contain measurements at |
conf.level |
Confidence level for mean raw response at each concentration. |
An object of class hook_effect containing concentration-level
summaries and one threshold result per series.
CLSI. Establishing and Verifying an Extended Measuring Interval Through Specimen Dilution and Spiking. EP34, 1st ed. 2018.
hook_data <- data.frame( concentration = rep(c(100, 200, 400, 800), each = 2), response = c(48, 52, 98, 102, 148, 152, 88, 92) ) hook <- hook_effect( hook_data, "concentration", "response", uloq = 200 ) hook$resultshook_data <- data.frame( concentration = rep(c(100, 200, 400, 800), each = 2), response = c(48, 52, 98, 102, 148, 152, 88, 92) ) hook <- hook_effect( hook_data, "concentration", "response", uloq = 200 ) hook$results
Summarizes replicate results at each interferent concentration relative to an observed baseline concentration. The recommended point-to-point method is the default; a straight-line regression can be requested explicitly.
interference_dose_response( data, result, concentration, by = NULL, baseline = 0, method = c("point_to_point", "linear"), conf.level = 0.95 )interference_dose_response( data, result, concentration, by = NULL, baseline = 0, method = c("point_to_point", "linear"), conf.level = 0.95 )
data |
Long-format data frame. |
result |
Numeric measurement-result column. |
concentration |
Numeric interferent-concentration column. |
by |
Optional stratification columns, typically interferent name and measurand level. |
baseline |
Observed interferent concentration used to estimate M0. |
method |
|
conf.level |
Confidence level for regression coefficients. |
An object of class interference_dose_response.
dose_data <- expand.grid( interferent = c("A", "B"), concentration = c(0, 10, 20, 30, 40), replicate = 1:5, KEEP.OUT.ATTRS = FALSE ) dose_data$result <- 100 + ifelse(dose_data$interferent == "A", 0.5, -0.3) * dose_data$concentration + stats::rnorm(nrow(dose_data), 0, 0.5) dose_fit <- interference_dose_response( dose_data, "result", "concentration", by = "interferent") dose_fit$summarydose_data <- expand.grid( interferent = c("A", "B"), concentration = c(0, 10, 20, 30, 40), replicate = 1:5, KEEP.OUT.ATTRS = FALSE ) dose_data$result <- 100 + ifelse(dose_data$interferent == "A", 0.5, -0.3) * dose_data$concentration + stats::rnorm(nrow(dose_data), 0, 0.5) dose_fit <- interference_dose_response( dose_data, "result", "concentration", by = "interferent") dose_fit$summary
Supports the standard EP07 test/control preparation and two laboratory
extensions: analyte spiking in normal/interferent matrices and direct
measurement of interferent dissolved in a blank. One row represents one
replicate result. Multiple interferents or measurand levels are handled by
supplying their columns in by.
interference_paired( data, result, design = c("ep07", "analyte_spike", "blank"), by = NULL, condition = NULL, test_level = "test", control_level = "control", matrix = NULL, normal_level = "normal", interferent_level = "interferent", spike = NULL, unspiked_level = "unspiked", spiked_level = "spiked", conf.level = 0.95 )interference_paired( data, result, design = c("ep07", "analyte_spike", "blank"), by = NULL, condition = NULL, test_level = "test", control_level = "control", matrix = NULL, normal_level = "normal", interferent_level = "interferent", spike = NULL, unspiked_level = "unspiked", spiked_level = "spiked", conf.level = 0.95 )
data |
Data frame in long format. |
result |
Numeric measurement-result column. |
design |
|
by |
Optional character vector of stratification columns. |
condition |
Test/control condition column for |
test_level |
Value identifying the test/interferent condition. |
control_level |
Value identifying the solvent control condition. |
matrix |
Matrix-type column for |
normal_level |
Value identifying the normal matrix. |
interferent_level |
Value identifying the interferent-containing matrix. |
spike |
Spike-status column for |
unspiked_level |
Value identifying measurements before analyte spiking. |
spiked_level |
Value identifying measurements after analyte spiking. |
conf.level |
Confidence level for intervals. |
An S3 object of class interference_paired containing effects,
cell_summary, issues, and excluded row indices.
ep07_data <- data.frame( interferent = rep(c("bilirubin", "hemoglobin"), each = 10), condition = rep(rep(c("control", "test"), each = 5), 2), result = c(0.45, 0.56, 0.48, 0.54, 0.47, 0.24, 0.28, 0.35, 0.37, 0.26, 5.02, 4.98, 5.08, 4.95, 5.00, 5.20, 5.12, 5.18, 5.10, 5.15) ) interference_paired(ep07_data, "result", design = "ep07", condition = "condition", by = "interferent") spike_data <- expand.grid( matrix = c("normal", "interferent"), spike = c("before", "after"), replicate = 1:4, KEEP.OUT.ATTRS = FALSE ) spike_data$result <- with(spike_data, ifelse(matrix == "normal", 10, 12) + ifelse(spike == "after", ifelse(matrix == "normal", 10, 8), 0)) interference_paired(spike_data, "result", design = "analyte_spike", matrix = "matrix", spike = "spike", unspiked_level = "before", spiked_level = "after")ep07_data <- data.frame( interferent = rep(c("bilirubin", "hemoglobin"), each = 10), condition = rep(rep(c("control", "test"), each = 5), 2), result = c(0.45, 0.56, 0.48, 0.54, 0.47, 0.24, 0.28, 0.35, 0.37, 0.26, 5.02, 4.98, 5.08, 4.95, 5.00, 5.20, 5.12, 5.18, 5.10, 5.15) ) interference_paired(ep07_data, "result", design = "ep07", condition = "condition", by = "interferent") spike_data <- expand.grid( matrix = c("normal", "interferent"), spike = c("before", "after"), replicate = 1:4, KEEP.OUT.ATTRS = FALSE ) spike_data$result <- with(spike_data, ifelse(matrix == "normal", 10, 12) + ifelse(spike == "after", ifelse(matrix == "normal", 10, 8), 0)) interference_paired(spike_data, "result", design = "analyte_spike", matrix = "matrix", spike = "spike", unspiked_level = "before", spiked_level = "after")
Averages replicates within specimen and method, then calculates the evaluated procedure result minus the comparative procedure result. Potential interferent concentrations can be supplied as multiple numeric columns and are modeled separately.
interference_patient( data, id, group, method, result, test_group, control_group, evaluated_method, comparative_method, interferent_cols = NULL, conf.level = 0.95 )interference_patient( data, id, group, method, result, test_group, control_group, evaluated_method, comparative_method, interferent_cols = NULL, conf.level = 0.95 )
data |
Long-format patient-result data. |
id |
Specimen identifier column. |
group |
Patient test/control group column. |
method |
Measurement-procedure column. |
result |
Numeric result column. |
test_group |
Value identifying the selected/test patient group. |
control_group |
Value identifying the control patient group. |
evaluated_method |
Value identifying the evaluated procedure. |
comparative_method |
Value identifying the comparative procedure. |
interferent_cols |
Optional numeric interferent-concentration columns. |
conf.level |
Confidence level for summaries and regression coefficients. |
An object of class interference_patient.
patient_data <- expand.grid( id = paste0("S", 1:12), method = c("evaluated", "comparative"), replicate = 1:2, KEEP.OUT.ATTRS = FALSE ) patient_data$group <- ifelse(as.integer(sub("S", "", patient_data$id)) <= 6, "control", "test") patient_data$bilirubin <- 2 * (as.integer(sub("S", "", patient_data$id)) - 1) truth <- 50 + as.integer(sub("S", "", patient_data$id)) patient_data$result <- truth + ifelse(patient_data$method == "evaluated", 0.08 * patient_data$bilirubin, 0) patient_fit <- interference_patient( patient_data, "id", "group", "method", "result", test_group = "test", control_group = "control", evaluated_method = "evaluated", comparative_method = "comparative", interferent_cols = "bilirubin") patient_fit$group_summarypatient_data <- expand.grid( id = paste0("S", 1:12), method = c("evaluated", "comparative"), replicate = 1:2, KEEP.OUT.ATTRS = FALSE ) patient_data$group <- ifelse(as.integer(sub("S", "", patient_data$id)) <= 6, "control", "test") patient_data$bilirubin <- 2 * (as.integer(sub("S", "", patient_data$id)) - 1) truth <- 50 + as.integer(sub("S", "", patient_data$id)) patient_data$result <- truth + ifelse(patient_data$method == "evaluated", 0.08 * patient_data$bilirubin, 0) patient_fit <- interference_patient( patient_data, "id", "group", "method", "result", test_group = "test", control_group = "control", evaluated_method = "evaluated", comparative_method = "comparative", interferent_cols = "bilirubin") patient_fit$group_summary
Calculates the number of replicate measurements needed in each of the test
and control samples. sd and detectable_difference must use the same
scale: both absolute units, or both relative units (SD/CV and percent).
The calculation is vectorized and reports design parameters only.
interference_replicates( sd, detectable_difference, alpha = 0.05, power = 0.9, alternative = c("two.sided", "one.sided"), min_replicates = 5L, label = NULL )interference_replicates( sd, detectable_difference, alpha = 0.05, power = 0.9, alternative = c("two.sided", "one.sided"), min_replicates = 5L, label = NULL )
sd |
Assumed repeatability SD, or repeatability CV when a relative calculation is intended. |
detectable_difference |
Smallest interference difference the experiment
is designed to detect, in the same units as |
alpha |
Type I error probability. |
power |
Desired statistical power. |
alternative |
|
min_replicates |
Minimum returned replicate count per test/control sample. |
label |
Optional labels, one per calculation. |
A data frame of class interference_replicates.
CLSI. Interference Testing in Clinical Chemistry. EP07, 3rd ed.
interference_replicates(sd = c(5, 5), detectable_difference = c(7, 10), label = c("7 percent", "10 percent"))interference_replicates(sd = c(5, 5), detectable_difference = c(7, 10), label = c("7 percent", "10 percent"))
Small deterministic one-way ANOVA example
ivd_bottle_exampleivd_bottle_example
A data frame with 12 observations from three bottles.
Small deterministic method-comparison example
ivd_mcr_exampleivd_mcr_example
A data frame with 12 rows and columns sid, test, and ref.
Small deterministic qualitative-method example
ivd_qualitative_exampleivd_qualitative_example
A data frame with paired binary results and sample identifiers.
Small deterministic ROC example
ivd_roc_exampleivd_roc_example
A data frame with 12 rows, two markers, and a binary reference.
Calculate Cohen's Kappa coefficient or PABAK (Prevalence-Adjusted Bias-Adjusted Kappa) and its confidence interval, used to evaluate agreement between two binary classification methods.
## S3 method for class 'fourfold_table' kappa(x, prevalence = NULL, conf.level = 0.95, ...)## S3 method for class 'fourfold_table' kappa(x, prevalence = NULL, conf.level = 0.95, ...)
x |
a fourfold_table object |
prevalence |
Patient prevalence. If provided, calculates PABAK instead of Cohen's Kappa. |
conf.level |
Confidence level, default 0.95 |
... |
Additional arguments (currently unused). |
When data prevalence is extreme, Cohen's Kappa may be low even when observed agreement is high.
In such cases, specify the prevalence parameter to compute PABAK as a correction.
PABAK = 2 x p_obs - 1, which assumes expected agreement = 0.5.
Updated fourfold_table object, with Kappa results stored in $kappa: - $kappa Kappa / PABAK coefficient - $se Standard error - $lower / $upper Lower/upper confidence interval bounds - $p_obs Observed agreement - $p_exp Expected agreement - $n Total sample size - $conf_level Confidence level used - $method Method name used
tab <- counts_to_table(tp = 85, fp = 3, tn = 90, fn = 2, candidate = "new method", reference = "gold standard") tab <- kappa(tab) # Cohen's Kappa tab <- kappa(tab, prevalence = 0.5) # PABAKtab <- counts_to_table(tp = 85, fp = 3, tn = 90, fn = 2, candidate = "new method", reference = "gold standard") tab <- kappa(tab) # Cohen's Kappa tab <- kappa(tab, prevalence = 0.5) # PABAK
linearity() is a parameter-driven analysis engine rather than a separate
validation/verification workflow. The straight-line calculations implement
the approach in CLSI EP06-Ed2. Polynomial regression reproduces the
superseded EP6-A procedure and is reported as exploratory. Straight-line
models are fitted to sample-level means; EP6-A polynomial models are fitted
to the retained replicate observations.
linearity( data, sample, result, x, method = c("linear", "polynomial"), intercept = TRUE, weights = c("equal", "level_variance", "pooled", "precision_profile"), variance_group = NULL, max_degree = 3L, poly_alpha = 0.05, percent_base = c("predicted", "x", "mean"), conf.level = NULL, multiplicity = c("familywise", "none"), adl = NULL, adl_abs = NULL, adl_rel = NULL, profile_exclude_low = TRUE, profile_intercept = FALSE )linearity( data, sample, result, x, method = c("linear", "polynomial"), intercept = TRUE, weights = c("equal", "level_variance", "pooled", "precision_profile"), variance_group = NULL, max_degree = 3L, poly_alpha = 0.05, percent_base = c("predicted", "x", "mean"), conf.level = NULL, multiplicity = c("familywise", "none"), adl = NULL, adl_abs = NULL, adl_rel = NULL, profile_exclude_low = TRUE, profile_intercept = FALSE )
data |
Data frame in long format, with one row per replicate result. |
sample |
Sample-level identifier column name. |
result |
Numeric measurement-result column name. |
x |
Numeric expected value, assigned value, relative concentration, or HIGH-proportion column name. Its value must be constant within a sample. |
method |
|
intercept |
Include an intercept in every fitted model? |
weights |
One of |
variance_group |
When |
max_degree |
Highest polynomial degree, 2 or 3. |
poly_alpha |
Significance level for EP6-A nonlinear coefficients. |
percent_base |
Denominator for percentage residuals and polynomial deviation from linearity: the straight-line prediction, x value, or observed sample mean. EP06-Ed2 examples use the prediction. |
conf.level |
Optional overall or pointwise confidence level for
straight-line residuals. Use |
multiplicity |
|
adl |
Optional direct absolute ADL, scalar or one value per level. |
adl_abs |
Optional fixed absolute ADL. |
adl_rel |
Optional relative ADL in percent. If more than one ADL form is supplied, the largest allowable value is used at each level. |
profile_exclude_low |
Exclude the lowest-x level from the precision profile and use its observed SD directly? |
profile_intercept |
Include an intercept in the SD-on-mean precision profile? EP06 uses a zero intercept. |
With weights = "pooled", variance groups must be supplied explicitly.
Within group g, the pooled variance is
sum((n[j] - 1) * s[j]^2) / sum(n[j] - 1), and the level-mean regression
weight is n[j] / pooled_variance[g]. The function does not infer groups
from the number of concentration levels because EP06 grouping also depends
on the observed repeatability pattern.
An S3 object of class linearity.
set.seed(2020) linearity_data <- data.frame( level = rep(1:6, each = 4), expected = rep(c(10, 30, 50, 70, 90, 110), each = 4) ) linearity_data$result <- 2 + 0.98 * linearity_data$expected + stats::rnorm(nrow(linearity_data), sd = 1.5) # Parameter-driven straight-line analysis. fit_linear <- linearity( linearity_data, sample = "level", result = "result", x = "expected", method = "linear", intercept = TRUE, weights = "level_variance", adl_rel = 5 ) fit_linear$model_comparison fit_linear$level_summary # EP6-A polynomial analysis (reported as exploratory under EP06-Ed2). fit_polynomial <- linearity( linearity_data, sample = "level", result = "result", x = "expected", method = "polynomial", max_degree = 3 ) fit_polynomial$coefficientsset.seed(2020) linearity_data <- data.frame( level = rep(1:6, each = 4), expected = rep(c(10, 30, 50, 70, 90, 110), each = 4) ) linearity_data$result <- 2 + 0.98 * linearity_data$expected + stats::rnorm(nrow(linearity_data), sd = 1.5) # Parameter-driven straight-line analysis. fit_linear <- linearity( linearity_data, sample = "level", result = "result", x = "expected", method = "linear", intercept = TRUE, weights = "level_variance", adl_rel = 5 ) fit_linear$model_comparison fit_linear$level_summary # EP6-A polynomial analysis (reported as exploratory under EP06-Ed2). fit_polynomial <- linearity( linearity_data, sample = "level", result = "result", x = "expected", method = "polynomial", max_degree = 3 ) fit_polynomial$coefficients
Implements the equations in Appendix J of CLSI EP06-Ed2 for studies in which results outside the measuring interval cannot be obtained.
linearity_endpoints( lloq = NULL, uloq = NULL, cv_high = NULL, cv_at_lloq = NULL, cv_at_k_lloq = NULL, k = 3, cv_scale = c("percent", "proportion") ) ## S3 method for class 'linearity_endpoints' print(x, ...)linearity_endpoints( lloq = NULL, uloq = NULL, cv_high = NULL, cv_at_lloq = NULL, cv_at_k_lloq = NULL, k = 3, cv_scale = c("percent", "proportion") ) ## S3 method for class 'linearity_endpoints' print(x, ...)
lloq |
Lower limit of quantitation. Supply with |
uloq |
Upper limit of quantitation. Supply with |
cv_high |
Repeatability CV near the upper limit. |
cv_at_lloq |
CV at the LLoQ. |
cv_at_k_lloq |
CV at |
k |
Concentration multiple for |
cv_scale |
Whether CV inputs are percentages or proportions. |
x |
A |
... |
Reserved arguments. |
A list of class linearity_endpoints.
The unchanged x, invisibly.
linearity_endpoints( lloq = 10, uloq = 1000, cv_high = 5, cv_at_lloq = 20, cv_at_k_lloq = 15 )linearity_endpoints( lloq = 10, uloq = 1000, cv_high = 5, cv_at_lloq = 20, cv_at_k_lloq = 15 )
Design a HIGH/LOW linearity panel
linearity_panel( proportion_high, high, low = 0, total_volume = NULL, sample = NULL ) ## S3 method for class 'linearity_panel' print(x, ...)linearity_panel( proportion_high, high, low = 0, total_volume = NULL, sample = NULL ) ## S3 method for class 'linearity_panel' print(x, ...)
proportion_high |
Proportion of the HIGH material at each level, between 0 and 1. |
high |
Assigned or measured value of the HIGH material. |
low |
Assigned or measured value of the LOW material; use zero for a HIGH/blank design. |
total_volume |
Optional total volume prepared at each level. |
sample |
Optional sample labels. |
x |
A |
... |
Reserved arguments. |
A data frame containing proportions, expected values, relative concentrations, and (when requested) component volumes.
The unchanged x, invisibly.
linearity_panel( proportion_high = c(1, 0.75, 0.5, 0.25, 0), high = 210, low = 10, total_volume = 1 )linearity_panel( proportion_high = c(1, 0.75, 0.5, 0.25, 0), high = 210, low = 10, total_volume = 1 )
Calculates the minimum number of replicates from the imprecision and
allowable deviation from linearity (ADL), following CLSI EP06-Ed2. Relative
inputs use percentage units (for example, 5 means 5%). Absolute inputs
must use the same measurement unit for imprecision, adl, and
true_deviation.
linearity_replicates( imprecision, adl, type = c("relative", "absolute"), level_probability = 0.99, levels = NULL, family_error = NULL, true_deviation = 0, min_replicates = 2L ) ## S3 method for class 'linearity_replicates' print(x, ...)linearity_replicates( imprecision, adl, type = c("relative", "absolute"), level_probability = 0.99, levels = NULL, family_error = NULL, true_deviation = 0, min_replicates = 2L ) ## S3 method for class 'linearity_replicates' print(x, ...)
imprecision |
Repeatability CV (percent) or SD (absolute units). |
adl |
Allowable deviation from linearity. |
type |
Either |
level_probability |
Desired central probability for an individual level. The EP06 default is 0.99. |
levels |
Optional number of concentration levels. Required when
|
family_error |
Optional overall risk that at least one level is outside
the ADL. When supplied, it replaces |
true_deviation |
Expected true deviation from linearity. It is
subtracted from |
min_replicates |
Smallest returned replicate count. |
x |
A |
... |
Reserved arguments. |
A data frame of class linearity_replicates.
The unchanged x, invisibly.
# Relative ADL: both CV and ADL are expressed in percent. linearity_replicates(imprecision = c(3, 5), adl = 5) # Choose the per-level probability from a 10% family-wise failure risk. linearity_replicates(5, 5, levels = 9, family_error = 0.10)# Relative ADL: both CV and ADL are expressed in percent. linearity_replicates(imprecision = c(3, 5), adl = 5) # Choose the per-level probability from a 10% family-wise failure risk. linearity_replicates(5, 5, levels = 9, family_error = 0.10)
Print the equation registry
list_equation(category = NULL, engine = NULL)list_equation(category = NULL, engine = NULL)
category |
filter category: "Response", or NULL (all) |
engine |
filter engine: "lm", "nls", or NULL (all) |
invisible data.frame (matching rows), prints a formatted table to the console
# All equations list_equation() # Response only list_equation(category = "Response") # lm engine only list_equation(engine = "lm")# All equations list_equation() # Response only list_equation(category = "Response") # lm engine only list_equation(engine = "lm")
List Sadler precision profile model equations
list_sadler()list_sadler()
This function has no arguments.
List the 10 candidate Sadler precision profile model formulas and types used in the VFP package. Includes: Constant SD, Constant CV, Linear (variance), Power model, Exponential model, etc.
Invisibly returns NULL. The model table is printed to the
console as a side effect.
list_sadler()list_sadler()
Prints commonly used Westgard multi-rule QC rules and their meanings.
Rule names printed here can be passed to qc_chart(rules = "...").
list_westgard(brief = FALSE)list_westgard(brief = FALSE)
brief |
Set to |
A named character vector of rule descriptions (invisibly).
list_westgard()list_westgard()
Perform McNemar's test on a 2x2 paired contingency table to evaluate whether there is a systematic difference between two binary classification methods (i.e., whether marginal probabilities are equal).
## S3 method for class 'fourfold_table' mcnemar(x, conf.level = 0.95, ...)## S3 method for class 'fourfold_table' mcnemar(x, conf.level = 0.95, ...)
x |
a fourfold_table object |
conf.level |
Confidence level, default 0.95 |
... |
Additional arguments (currently unused). |
When discordant pairs (b + c) are few (< 25), automatically uses the exact binomial test (binom.test); otherwise uses McNemar's chi-squared test with continuity correction.
Updated fourfold_table object, with McNemar results stored in $mcnemar: - $chi_sq McNemar chi-squared statistic (NA for exact test) - $df Degrees of freedom (NA for exact test) - $p_value Test p-value - $method Test method used - $b Discordant pairs (positive, negative) count - $c Discordant pairs (negative, positive) count - $n_bc Total discordant pairs - $conf.level Confidence level used
tab <- counts_to_table(tp = 45, fp = 12, tn = 80, fn = 5, candidate = "new method", reference = "gold standard") tab <- mcnemar(tab)tab <- counts_to_table(tp = 45, fp = 12, tn = 80, fn = 5, candidate = "new method", reference = "gold standard") tab <- mcnemar(tab)
Create a method comparison regression (mcr) object containing one summarized
row per sample ID. Raw replicate rows must first be summarized with
replicate_to_mean() or by the user.
mcr( data, id, candidate, reference, weights = NULL, candidate_sd = NULL, reference_sd = NULL, candidate_n = NULL, reference_n = NULL )mcr( data, id, candidate, reference, weights = NULL, candidate_sd = NULL, reference_sd = NULL, candidate_n = NULL, reference_n = NULL )
data |
Data frame with id, candidate, reference columns |
id |
ID variable name (character), used to identify samples |
candidate |
Candidate/test method variable name (character), used as the response (Y) throughout regression and plotting. |
reference |
Reference/comparative method variable name (character), used as the predictor (X) throughout regression and plotting. |
weights |
Optional column name (character) in data containing non-negative finite numeric weights for weighted regression. Default NULL (no weighting). |
candidate_sd, reference_sd
|
Optional column names containing within-sample
SDs for summarized replicate data. Supply both when |
candidate_n, reference_n
|
Optional column names containing replicate counts for summarized data. Supply both or neither. Without them, equal replicate counts are assumed and cancel from the variance ratio. |
Returns an S3 "mcr" object containing:
call |
Original function call |
data |
Complete data frame |
id / id_name |
ID vector and column name |
candidate / reference |
Test/reference method numeric vectors (complete pairs only) |
candidate_name / reference_name |
Method column names |
n |
Number of complete pairs |
complete_idx |
Row indices of complete pairs in the original data |
and analysis result storage slots: $correlation, $regression, $outlier, $bland_altman
df <- data.frame(sid = 1:30, test = rnorm(30, 50, 10), ref = rnorm(30, 50, 10)) obj <- mcr(df, "sid", "test", "ref")df <- data.frame(sid = 1:30, test = rnorm(30, 50, 10), ref = rnorm(30, 50, 10)) obj <- mcr(df, "sid", "test", "ref")
Calculates the mean kinetic temperature from one or more temperature probes. Supports equal-interval and time-weighted trapezoidal methods.
mkt(data, temp_cols, time = NULL, temp_unit = "C", ea = 83.144)mkt(data, temp_cols, time = NULL, temp_unit = "C", ea = 83.144)
data |
A data frame. |
temp_cols |
One or more column names for temperature probes. |
time |
Optional time column; accepts numeric, Date, or POSIXct. |
temp_unit |
Temperature unit: |
ea |
Activation energy in kJ/mol; default 83.144. |
An S3 object of class "mkt".
temp_df <- data.frame(t1 = c(25,26,27), t2 = c(24,25,26), time = 1:3) mkt(temp_df, c("t1","t2"), "time")temp_df <- data.frame(t1 = c(25,26,27), t2 = c(24,25,26), time = 1:3) mkt(temp_df, c("t1","t2"), "time")
Fit logistic regression using selected evaluation columns, compute AUC of predicted probabilities. Names must be unique; auto-generated as MLR01, MLR02 ... when not specified.
## S3 method for class 'roc' mlr(x, cols = NULL, name = NULL, ...)## S3 method for class 'roc' mlr(x, cols = NULL, name = NULL, ...)
x |
roc object |
cols |
column names to fit; default is all |
name |
fit name (must be unique); auto-generated by default |
... |
additional arguments passed to glm |
Updated roc object with results stored in $mlr_results[name]
obj <- roc(ivd_roc_example, cols = c("x1", "x2"), reference = "ref") obj <- auc(obj) obj <- mlr(obj) # -> MLR01 obj <- mlr(obj) # -> MLR02 obj <- mlr(obj, name = "my_model") # -> my_modelobj <- roc(ivd_roc_example, cols = c("x1", "x2"), reference = "ref") obj <- auc(obj) obj <- mlr(obj) # -> MLR01 obj <- mlr(obj) # -> MLR02 obj <- mlr(obj, name = "my_model") # -> my_model
Performs normality tests on a single numeric column of a data frame.
Plots are generated separately via plot().
normal_test( data, col, method = c("auto", "shapiro", "sw", "ad", "lillie", "cvm"), level = 0.95 )normal_test( data, col, method = c("auto", "shapiro", "sw", "ad", "lillie", "cvm"), level = 0.95 )
data |
A data frame. |
col |
Column name to test (single string). |
method |
Test method: "auto" (default, chooses by sample size), "shapiro"/"sw", "ad", "lillie", "cvm". |
level |
Confidence level (default 0.95, used for QQ confidence bands). |
An S3 object of class "normal_test" containing:
callFunction call.
data_nameData object name.
colColumn name.
methodUser-specified method.
levelConfidence level.
n_totalTotal number of rows.
nNumber of finite values (non-missing).
missingNumber of missing values.
test_methodActual test method used.
statisticTest statistic.
p_valuep-value.
yClean numeric vector, used by plot().
df <- data.frame(x = rnorm(50)) normal_test(df, "x") normal_test(df, "x", method = "ad") plot(normal_test(df, "x")) plot(normal_test(df, "x"), type = "his") plot(normal_test(df, "x"), type = c("qq", "his"))df <- data.frame(x = rnorm(50)) normal_test(df, "x") normal_test(df, "x", method = "ad") plot(normal_test(df, "x")) plot(normal_test(df, "x"), type = "his") plot(normal_test(df, "x"), type = c("qq", "his"))
Perform normality tests on the response values for each sample, underlying call to normal_test().
Supports automatic test selection (Shapiro-Wilk, Anderson-Darling, Lilliefors, CVM).
## S3 method for class 'precision' normal( x, method = c("auto", "shapiro", "sw", "ad", "lillie", "cvm"), level = 0.95, ... )## S3 method for class 'precision' normal( x, method = c("auto", "shapiro", "sw", "ad", "lillie", "cvm"), level = 0.95, ... )
x |
|
method |
Test method: |
level |
Confidence level, default |
... |
Reserved arguments |
Updated precision object with results stored in $normal.
Each sample entry contains test_method, statistic_name,
statistic, p_value, and n; W is retained as a
legacy alias only for Shapiro-Wilk results.
data(VCAdata1, package = "VCA") obj <- precision(VCAdata1, y ~ day/run, by = "sample") obj <- normal(obj)data(VCAdata1, package = "VCA") obj <- precision(VCAdata1, y ~ day/run, by = "sample") obj <- normal(obj)
Detect outliers in an analysis object
outlier(x, ...)outlier(x, ...)
x |
An S3 analysis object. |
... |
Additional arguments passed to a method. |
The value returned by the dispatched method.
obj <- mcr(ivd_mcr_example, "sid", "test", "ref") outlier(obj, method = "grubbs")obj <- mcr(ivd_mcr_example, "sid", "test", "ref") outlier(obj, method = "grubbs")
Perform outlier detection based on the difference or percent difference between two measurements. Reuses four methods from ../precision/outliers.R.
## S3 method for class 'mcr' outlier( x, method = c("grubbs", "esd", "dixon", "iqr"), type = c("difference", "percent"), percent_denominator = c("reference", "mean", "candidate"), alpha = 0.05, coef = 1.5, ... )## S3 method for class 'mcr' outlier( x, method = c("grubbs", "esd", "dixon", "iqr"), type = c("difference", "percent"), percent_denominator = c("reference", "mean", "candidate"), alpha = 0.05, coef = 1.5, ... )
x |
mcr object |
method |
Outlier detection method: "grubbs" (default), "esd", "dixon", "iqr" |
type |
Data type to compute: "difference" (default) or "percent" (percent difference) |
percent_denominator |
Denominator for percent differences: reference (default), pair mean, or candidate. |
alpha |
Significance level, default 0.05 (Grubbs/ESD/Dixon only) |
coef |
IQR multiplier, default 1.5 (IQR only) |
... |
Additional arguments passed to esd_test / dixon_test |
Updated mcr object (invisible), results stored in $outlier
obj <- mcr(ivd_mcr_example, "sid", "test", "ref") outlier(obj, method = "grubbs") outlier(obj, method = "iqr", type = "percent")obj <- mcr(ivd_mcr_example, "sid", "test", "ref") outlier(obj, method = "grubbs") outlier(obj, method = "iqr", type = "percent")
Detect outliers in the response values for each sample, supporting Grubbs test and IQR method.
Underlying call to outliers_test() (from outliers-and-normal.R).
## S3 method for class 'precision' outlier(x, alpha = 0.05, method = c("grubbs", "iqr"), ...)## S3 method for class 'precision' outlier(x, alpha = 0.05, method = c("grubbs", "iqr"), ...)
x |
|
alpha |
Significance level, default |
method |
Detection method: |
... |
Additional arguments passed to |
Updated precision object with results stored in $outlier
data(VCAdata1, package = "VCA") obj <- precision(VCAdata1, y ~ day/run, by = "sample") obj <- outlier(obj, method = "iqr")data(VCAdata1, package = "VCA") obj <- precision(VCAdata1, y ~ day/run, by = "sample") obj <- outlier(obj, method = "iqr")
Integrates Grubbs test, generalized ESD test, Dixon Q test, and IQR method under a consistent API with an S3 print method.
outliers_test(data, col, method = c("grubbs", "esd", "dixon", "iqr"), ...)outliers_test(data, col, method = c("grubbs", "esd", "dixon", "iqr"), ...)
data |
A data frame. |
col |
Column name to test (single string). |
method |
Detection method: "grubbs" (default), "esd", "dixon", "iqr". |
... |
Additional arguments passed to internal methods:
|
An S3 object of class "outliers_test" containing:
methodMethod name used.
data_nameName of the input data.
colColumn name tested.
n_totalTotal number of rows.
nNumber of finite observations used.
missingNumber of missing (non-finite) values.
parametersList of method parameters.
n_outliersNumber of outliers detected.
indicesIndices of outliers in the original vector (1-based).
valuesOutlier values.
detailsMethod-specific details (statistics, critical values, bounds, etc.).
set.seed(123) df <- data.frame(x = c(rnorm(20), 10, -8)) outliers_test(df, "x", "grubbs") outliers_test(df, "x", "esd", r = 3) outliers_test(df, "x", "dixon") outliers_test(df, "x", "iqr", coef = 2)set.seed(123) df <- data.frame(x = c(rnorm(20), 10, -8)) outliers_test(df, "x", "grubbs") outliers_test(df, "x", "esd", r = 3) outliers_test(df, "x", "dixon") outliers_test(df, "x", "iqr", coef = 2)
Plot Arrhenius stability analysis
## S3 method for class 'arrhenius' plot(x, ...)## S3 method for class 'arrhenius' plot(x, ...)
x |
An |
... |
Reserved for the S3 generic. |
A named list of ggplot objects, invisibly. The kinetic-fit
and Arrhenius-regression plots are also drawn.
d <- data.frame( temperature = rep(c(25, 30, 37), each = 3), time = rep(c(0, 1, 3), 3), value = c(100, 98, 95, 100, 96, 90, 100, 94, 85) ) fit <- arrhenius(d, "temperature", "time", "value", target_temp = 5, limit = 10) plot(fit)d <- data.frame( temperature = rep(c(25, 30, 37), each = 3), time = rep(c(0, 1, 3), 3), value = c(100, 98, 95, 100, 96, 90, 100, 94, 85) ) fit <- arrhenius(d, "temperature", "time", "value", target_temp = 5, limit = 10) plot(fit)
Plot C5 and C95 results
## S3 method for class 'c5_c95' plot(x, type = c("probability", "profile"), ...)## S3 method for class 'c5_c95' plot(x, type = c("probability", "profile"), ...)
x |
A |
type |
Plot type: |
... |
Reserved arguments. |
A ggplot object.
set.seed(95) d <- data.frame(level = rep(1:6, each = 12), y = stats::rnorm(72, rep(seq(36, 44, length.out = 6), each = 12), 1)) z <- c5_c95(d, "y", "level", cutoff = 40, model.no = 1) plot(z, type = "probability")set.seed(95) d <- data.frame(level = rep(1:6, each = 12), y = stats::rnorm(72, rep(seq(36, 44, length.out = 6), each = 12), 1)) z <- c5_c95(d, "y", "level", cutoff = 40, model.no = 1) plot(z, type = "probability")
Plot a commutability assessment
## S3 method for class 'commutability_result' plot(x, method = NULL, ...)## S3 method for class 'commutability_result' plot(x, method = NULL, ...)
x |
A |
method |
For EP30, either |
... |
Reserved arguments. |
A ggplot object, invisibly.
clinical <- expand.grid( sample = paste0("CS", 1:8), procedure = c("MP1", "MP2"), replicate = 1:3, stringsAsFactors = FALSE ) level <- setNames(seq(10, 80, length.out = 8), paste0("CS", 1:8)) clinical$result <- level[clinical$sample] + ifelse(clinical$procedure == "MP2", 1, 0) + rep(c(-0.2, 0, 0.2), each = 16) clinical$material_type <- "clinical" clinical$position <- NA_integer_ rm <- expand.grid( sample = "RM1", procedure = c("MP1", "MP2"), position = 1:3, replicate = 1:3, stringsAsFactors = FALSE ) rm$result <- 45 + ifelse(rm$procedure == "MP2", 1, 0) + rep(c(-0.1, 0, 0.1), each = 6) rm$material_type <- "rm" columns <- c("sample", "material_type", "procedure", "result", "position", "replicate") example_data <- rbind(clinical[columns], rm[columns]) assessment <- commutability( example_data, "sample", "material_type", "procedure", "result" ) plot(assessment)clinical <- expand.grid( sample = paste0("CS", 1:8), procedure = c("MP1", "MP2"), replicate = 1:3, stringsAsFactors = FALSE ) level <- setNames(seq(10, 80, length.out = 8), paste0("CS", 1:8)) clinical$result <- level[clinical$sample] + ifelse(clinical$procedure == "MP2", 1, 0) + rep(c(-0.2, 0, 0.2), each = 16) clinical$material_type <- "clinical" clinical$position <- NA_integer_ rm <- expand.grid( sample = "RM1", procedure = c("MP1", "MP2"), position = 1:3, replicate = 1:3, stringsAsFactors = FALSE ) rm$result <- 45 + ifelse(rm$procedure == "MP2", 1, 0) + rep(c(-0.1, 0, 0.1), each = 6) rm$material_type <- "rm" columns <- c("sample", "material_type", "procedure", "result", "position", "replicate") example_data <- rbind(clinical[columns], rm[columns]) assessment <- commutability( example_data, "sample", "material_type", "procedure", "result" ) plot(assessment)
Plot dilution-recovery results
## S3 method for class 'dilution_recovery' plot(x, type = c("recovery", "summary", "observed"), ...)## S3 method for class 'dilution_recovery' plot(x, type = c("recovery", "summary", "observed"), ...)
x |
A |
type |
|
... |
Reserved arguments. |
A ggplot object, invisibly.
dilution_data <- data.frame( sample = rep(c("S1", "S2"), each = 6), factor = rep(rep(c(1, 2, 4), each = 2), 2), result = c(99, 101, 49, 51, 24, 26, 199, 201, 99, 101, 49, 51) ) dilution <- dilution_recovery( dilution_data, "sample", "result", "factor" ) plot(dilution)dilution_data <- data.frame( sample = rep(c("S1", "S2"), each = 6), factor = rep(rep(c(1, 2, 4), each = 2), 2), result = c(99, 101, 49, 51, 24, 26, 199, 201, 99, 101, 49, 51) ) dilution <- dilution_recovery( dilution_data, "sample", "result", "factor" ) plot(dilution)
Plot an equation fit
## S3 method for class 'fit_equation' plot(x, interval = "confidence", level = 0.95, frame = FALSE, ...)## S3 method for class 'fit_equation' plot(x, interval = "confidence", level = 0.95, frame = FALSE, ...)
x |
A |
interval |
Interval type, either |
level |
Confidence level. |
frame |
Whether to draw a frame. |
... |
Additional arguments (currently unused). |
x, invisibly.
df4plc <- data.frame( conc = c(0.1, 0.3, 1, 3, 10, 30, 100), resp = c(12, 25, 48, 72, 88, 96, 99) ) f <- fit_equation("E07", df4plc, "conc", "resp") plot(f) plot(f, interval = "prediction", frame = TRUE)df4plc <- data.frame( conc = c(0.1, 0.3, 1, 3, 10, 30, 100), resp = c(12, 25, 48, 72, 88, 96, 99) ) f <- fit_equation("E07", df4plc, "conc", "resp") plot(f) plot(f, interval = "prediction", frame = TRUE)
Plot a high-dose hook-effect experiment
## S3 method for class 'hook_effect' plot(x, ...)## S3 method for class 'hook_effect' plot(x, ...)
x |
A |
... |
Reserved arguments. |
A ggplot object, invisibly.
hook_data <- data.frame( series = rep("S1", 8), concentration = rep(c(10, 20, 40, 80, 160, 320, 640, 1280), each = 2), response = c(10, 11, 20, 21, 39, 40, 70, 71, 95, 94, 80, 79, 55, 54, 30, 29) ) hook <- hook_effect(hook_data, "concentration", "response", series = "series", uloq = 320) plot(hook)hook_data <- data.frame( series = rep("S1", 8), concentration = rep(c(10, 20, 40, 80, 160, 320, 640, 1280), each = 2), response = c(10, 11, 20, 21, 39, 40, 70, 71, 95, 94, 80, 79, 55, 54, 30, 29) ) hook <- hook_effect(hook_data, "concentration", "response", series = "series", uloq = 320) plot(hook)
Plot interference dose-response results
## S3 method for class 'interference_dose_response' plot(x, type = c("response", "absolute", "percent"), ...)## S3 method for class 'interference_dose_response' plot(x, type = c("response", "absolute", "percent"), ...)
x |
An |
type |
|
... |
Unused. |
A ggplot object.
d <- expand.grid(conc = c(0, 10, 20), rep = 1:5) d$result <- 100 + 0.5 * d$conc plot(interference_dose_response(d, "result", "conc"), type = "percent")d <- expand.grid(conc = c(0, 10, 20), rep = 1:5) d$result <- 100 + 0.5 * d$conc plot(interference_dose_response(d, "result", "conc"), type = "percent")
Plot paired interference estimates
## S3 method for class 'interference_paired' plot(x, ...)## S3 method for class 'interference_paired' plot(x, ...)
x |
An |
... |
Unused. |
A ggplot object.
d <- data.frame(group = rep(c("control", "test"), each = 5), result = c(10, 10.1, 9.9, 10.2, 9.8, 11, 11.1, 10.9, 11.2, 10.8)) plot(interference_paired(d, "result", "ep07", condition = "group"))d <- data.frame(group = rep(c("control", "test"), each = 5), result = c(10, 10.1, 9.9, 10.2, 9.8, 11, 11.1, 10.9, 11.2, 10.8)) plot(interference_paired(d, "result", "ep07", condition = "group"))
Plot patient-specimen interference results
## S3 method for class 'interference_patient' plot(x, type = c("difference", "interferent"), interferent = NULL, ...)## S3 method for class 'interference_patient' plot(x, type = c("difference", "interferent"), interferent = NULL, ...)
x |
An |
type |
|
interferent |
Interferent concentration column to plot when
|
... |
Unused. |
A ggplot object.
d <- expand.grid(id = paste0("S", 1:8), method = c("test", "ref"), rep = 1:2) d$group <- ifelse(as.integer(sub("S", "", d$id)) <= 4, "control", "selected") d$bilirubin <- 2 * (as.integer(sub("S", "", d$id)) - 1) d$result <- 20 + as.integer(sub("S", "", d$id)) + ifelse(d$method == "test", 0.1 * d$bilirubin, 0) fit <- interference_patient(d, "id", "group", "method", "result", "selected", "control", "test", "ref", "bilirubin") plot(fit, type = "difference")d <- expand.grid(id = paste0("S", 1:8), method = c("test", "ref"), rep = 1:2) d$group <- ifelse(as.integer(sub("S", "", d$id)) <= 4, "control", "selected") d$bilirubin <- 2 * (as.integer(sub("S", "", d$id)) - 1) d$result <- 20 + as.integer(sub("S", "", d$id)) + ifelse(d$method == "test", 0.1 * d$bilirubin, 0) fit <- interference_patient(d, "id", "group", "method", "result", "selected", "control", "test", "ref", "bilirubin") plot(fit, type = "difference")
Plot a linearity analysis
## S3 method for class 'linearity' plot( x, type = c("fit", "replicates", "precision", "residual", "difference"), ... )## S3 method for class 'linearity' plot( x, type = c("fit", "replicates", "precision", "residual", "difference"), ... )
x |
A |
type |
One of |
... |
Reserved for future use. |
A ggplot object.
set.seed(6) d <- data.frame(level = rep(1:5, each = 3), x = rep(1:5, each = 3)) d$y <- 1 + 2 * d$x + stats::rnorm(nrow(d), sd = 0.2) fit <- linearity(d, "level", "y", "x") plot(fit, type = "fit") plot(fit, type = "residual")set.seed(6) d <- data.frame(level = rep(1:5, each = 3), x = rep(1:5, each = 3)) d$y <- 1 + 2 * d$x + stats::rnorm(nrow(d), sd = 0.2) fit <- linearity(d, "level", "y", "x") plot(fit, type = "fit") plot(fit, type = "residual")
Draw one of four plot types for an mcr object.
## S3 method for class 'mcr' plot( x, type = c("scatter", "regression", "bland_altman", "bias"), interval = c("none", "confidence", "prediction", "both"), conf.level = NULL, mdl = NULL, ... )## S3 method for class 'mcr' plot( x, type = c("scatter", "regression", "bland_altman", "bias"), interval = c("none", "confidence", "prediction", "both"), conf.level = NULL, mdl = NULL, ... )
x |
mcr object |
type |
Plot type: "scatter" (scatter + identity line, default), "regression" (regression line + confidence/prediction bands), "bland_altman" (Bland-Altman plot), "bias" (bias trend plot) |
interval |
Interval type (only for type="regression"): "none" (default), "confidence", "prediction", "both" |
conf.level |
Confidence level; if NULL, reads from analysis slot, otherwise uses this value |
mdl |
Medical decision levels (only for type="bias"); if NULL, tries to read from x$bias$mdl |
... |
Additional arguments |
Invisible ggplot object
obj <- mcr(ivd_mcr_example, "sid", "test", "ref") plot(obj) plot(obj, type = "scatter") obj <- regression(obj) plot(obj, type = "regression", interval = "confidence") obj <- bland_altman(obj) plot(obj, type = "bland_altman") obj <- bias(obj, mdl = c(200, 400)) plot(obj, type = "bias")obj <- mcr(ivd_mcr_example, "sid", "test", "ref") plot(obj) plot(obj, type = "scatter") obj <- regression(obj) plot(obj, type = "regression", interval = "confidence") obj <- bland_altman(obj) plot(obj, type = "bland_altman") obj <- bias(obj, mdl = c(200, 400)) plot(obj, type = "bias")
Plot normality diagnostics
## S3 method for class 'normal_test' plot(x, type = c("qq", "his"), ...)## S3 method for class 'normal_test' plot(x, type = c("qq", "his"), ...)
x |
A |
type |
One or both of |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly; requested plots are drawn as a
side effect. For fewer than three observations no plot is drawn.
d <- data.frame(value = rnorm(30)) nt <- normal_test(d, "value") plot(nt, type = c("qq", "his"))d <- data.frame(value = rnorm(30)) nt <- normal_test(d, "value") plot(nt, type = c("qq", "his"))
Draw one of five plot types for a precision object. dot (run-order scatter plot) and
his (histogram + N(0,1) density) require no prior analysis; var (variance component bar chart)
requires variance() to be run first; qq (normal Q-Q plot) requires normal() first;
profile (precision profile) requires profile() first.
## S3 method for class 'precision' plot(x, type = c("dot", "his", "var", "qq", "profile"), ...)## S3 method for class 'precision' plot(x, type = c("dot", "his", "var", "qq", "profile"), ...)
x |
|
type |
Plot type: |
... |
Reserved arguments |
Invisible ggplot object
data(VCAdata1, package = "VCA") obj <- precision(VCAdata1, y ~ day/run, by = "sample") plot(obj, type = "dot") plot(obj, type = "his")data(VCAdata1, package = "VCA") obj <- precision(VCAdata1, y ~ day/run, by = "sample") plot(obj, type = "dot") plot(obj, type = "his")
Plot a Levey-Jennings QC chart
## S3 method for class 'qc_chart' plot(x, ...)## S3 method for class 'qc_chart' plot(x, ...)
x |
A |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly; the chart is drawn as a side
effect.
set.seed(42) d <- data.frame(value = rnorm(30, 100, 5), run = 1:30) plot(qc_chart(d, "value", run = "run"))set.seed(42) d <- data.frame(value = rnorm(30, 100, 5), run = 1:30) plot(qc_chart(d, "value", run = "run"))
One panel per method: jitter strip chart overlaid with reference interval limits, endpoints, and CI error bars.
## S3 method for class 'reference_interval' plot(x, ...)## S3 method for class 'reference_interval' plot(x, ...)
x |
A "reference_interval" object. |
... |
Additional arguments (reserved for generic). |
A ggplot object, invisibly. The plot is also drawn as a side
effect.
set.seed(11) d <- data.frame(value = rnorm(120, 100, 15)) ri <- reference_interval(d, "value") plot(ri)set.seed(11) d <- data.frame(value = rnorm(120, 100, 15)) ri <- reference_interval(d, "value") plot(ri)
Draw ROC curves for evaluation columns and/or MLR model predictions, or draw
sensitivity and specificity as functions of the cutoff for one evaluation
column. Optionally mark optimal cutoff points (requires cutoff.roc()
first).
## S3 method for class 'roc' plot(x, curves = NULL, cutpoint = NULL, type = c("roc", "cutoff"), ...)## S3 method for class 'roc' plot(x, curves = NULL, cutpoint = NULL, type = c("roc", "cutoff"), ...)
x |
roc object |
curves |
ROC curve names to plot. Names can refer to original marker
columns or stored MLR models. |
cutpoint |
mark optimal cutoff points: |
type |
|
... |
unused; supplying additional arguments is an error. |
invisible ggplot object
obj <- roc(ivd_roc_example, cols = c("x1", "x2"), reference = "ref") obj <- auc(obj) plot(obj) plot(obj, curves = "x1") # AUC calculation is not needed for the cutoff-dependent metric plot. plot(roc(ivd_roc_example, cols = "x1", reference = "ref"), curves = "x1", type = "cutoff") obj <- auc(obj); obj <- cutoff(obj); obj <- mlr(obj) plot(obj, curves = "all", cutpoint = "Youden") plot(obj, curves = "x1", type = "cutoff", cutpoint = "Youden")obj <- roc(ivd_roc_example, cols = c("x1", "x2"), reference = "ref") obj <- auc(obj) plot(obj) plot(obj, curves = "x1") # AUC calculation is not needed for the cutoff-dependent metric plot. plot(roc(ivd_roc_example, cols = "x1", reference = "ref"), curves = "x1", type = "cutoff") obj <- auc(obj); obj <- cutoff(obj); obj <- mlr(obj) plot(obj, curves = "all", cutpoint = "Youden") plot(obj, curves = "x1", type = "cutoff", cutpoint = "Youden")
Plot an analytical-sensitivity analysis
## S3 method for class 'sensitivity' plot(x, ...)## S3 method for class 'sensitivity' plot(x, ...)
x |
A sensitivity-analysis result object. |
... |
Reserved for the S3 generic. |
A ggplot object.
d <- data.frame(sample = rep("blank", 10), result = seq(0.1, 1, length.out = 10)) fit <- sensitivity_lob(d, "result", "sample") plot(fit)d <- data.frame(sample = rep("blank", 10), result = seq(0.1, 1, length.out = 10)) fit <- sensitivity_lob(d, "result", "sample") plot(fit)
Plot spike-recovery results
## S3 method for class 'spike_recovery' plot(x, ...)## S3 method for class 'spike_recovery' plot(x, ...)
x |
A |
... |
Reserved arguments. |
A ggplot object, invisibly.
spike_data <- data.frame( sample = rep(c("S1", "S2"), each = 4), condition = rep(rep(c("spiked", "control"), each = 2), 2), result = c(20.1, 19.9, 10.0, 10.2, 30.2, 29.8, 20.1, 19.9) ) recovery <- spike_recovery( spike_data, "sample", "result", "condition", analyte_level = "spiked", solvent_level = "control", added_concentration = 10 ) plot(recovery)spike_data <- data.frame( sample = rep(c("S1", "S2"), each = 4), condition = rep(rep(c("spiked", "control"), each = 2), 2), result = c(20.1, 19.9, 10.0, 10.2, 30.2, 29.8, 20.1, 19.9) ) recovery <- spike_recovery( spike_data, "sample", "result", "condition", analyte_level = "spiked", solvent_level = "control", added_concentration = 10 ) plot(recovery)
Plot stability bias across storage conditions
## S3 method for class 'stability_bias' plot(x, ...)## S3 method for class 'stability_bias' plot(x, ...)
x |
A |
... |
Reserved for the S3 generic. |
A ggplot object, invisibly; the plot is also drawn.
d <- data.frame( condition = rep("2-8C", each = 8), time = rep(c(0, 1, 3, 7), 2), value = c(100, 99.8, 99.4, 98.9, 100.2, 99.9, 99.5, 98.8) ) plot(stability_bias(d, "condition", "time", "value"))d <- data.frame( condition = rep("2-8C", each = 8), time = rep(c(0, 1, 3, 7), 2), value = c(100, 99.8, 99.4, 98.9, 100.2, 99.9, 99.5, 98.8) ) plot(stability_bias(d, "condition", "time", "value"))
Plot a stability regression
## S3 method for class 'stability_regression' plot(x, ...)## S3 method for class 'stability_regression' plot(x, ...)
x |
A |
... |
Reserved for the S3 generic. |
A ggplot object, invisibly; the plot is also drawn.
d <- data.frame( condition = rep("2-8C", each = 8), time = rep(c(0, 1, 3, 7), 2), value = c(100, 99.8, 99.4, 98.9, 100.2, 99.9, 99.5, 98.8) ) fit <- stability_regression(d, "time", "value", "condition") plot(fit)d <- data.frame( condition = rep("2-8C", each = 8), time = rep(c(0, 1, 3, 7), 2), value = c(100, 99.8, 99.4, 98.9, 100.2, 99.9, 99.5, 98.8) ) fit <- stability_regression(d, "time", "value", "condition") plot(fit)
Plot stability limit-time predictions
## S3 method for class 'stability_time' plot(x, ...)## S3 method for class 'stability_time' plot(x, ...)
x |
A |
... |
Reserved for the S3 generic. |
A ggplot object, invisibly; the plot is also drawn.
d <- data.frame( condition = rep("2-8C", each = 8), time = rep(c(0, 1, 3, 7), 2), value = c(100, 99.8, 99.4, 98.9, 100.2, 99.9, 99.5, 98.8) ) fit <- stability_regression(d, "time", "value", "condition") limit_time <- stability_time(fit, limit = 5) plot(limit_time)d <- data.frame( condition = rep("2-8C", each = 8), time = rep(c(0, 1, 3, 7), 2), value = c(100, 99.8, 99.4, 98.9, 100.2, 99.9, 99.5, 98.8) ) fit <- stability_regression(d, "time", "value", "condition") limit_time <- stability_time(fit, limit = 5) plot(limit_time)
Plot an uncertainty budget
## S3 method for class 'uncertainty_budget' plot(x, ...)## S3 method for class 'uncertainty_budget' plot(x, ...)
x |
An |
... |
Reserved arguments. |
A ggplot object, invisibly.
repeatability <- uncertainty_type_a( c(9.9, 10.0, 10.1, 10.0), "repeatability", quantity = "mean" ) calibrator <- uncertainty_type_b( "calibrator", estimate = 10, uncertainty = 0.2, k = 2, distribution = "normal" ) budget <- uncertainty_combine(repeatability, calibrator, value = 10) plot(budget)repeatability <- uncertainty_type_a( c(9.9, 10.0, 10.1, 10.0), "repeatability", quantity = "mean" ) calibrator <- uncertainty_type_b( "calibrator", estimate = 10, uncertainty = 0.2, k = 2, distribution = "normal" ) budget <- uncertainty_combine(repeatability, calibrator, value = 10) plot(budget)
Plot propagated uncertainty
## S3 method for class 'uncertainty_propagation' plot(x, type = c("distribution", "contribution"), ...)## S3 method for class 'uncertainty_propagation' plot(x, type = c("distribution", "contribution"), ...)
x |
An |
type |
|
... |
Reserved arguments. |
A ggplot object, invisibly.
numerator <- uncertainty_type_b( "numerator", estimate = 10, uncertainty = 0.2, k = 2, distribution = "normal" ) denominator <- uncertainty_type_b( "denominator", estimate = 2, uncertainty = 0.04, k = 2, distribution = "normal" ) propagated <- uncertainty_propagate( function(numerator, denominator) numerator / denominator, list(numerator, denominator), method = "delta" ) plot(propagated, type = "contribution")numerator <- uncertainty_type_b( "numerator", estimate = 10, uncertainty = 0.2, k = 2, distribution = "normal" ) denominator <- uncertainty_type_b( "denominator", estimate = 2, uncertainty = 0.04, k = 2, distribution = "normal" ) propagated <- uncertainty_propagate( function(numerator, denominator) numerator / denominator, list(numerator, denominator), method = "delta" ) plot(propagated, type = "contribution")
Plot cumulative uncertainty through a traceability chain
## S3 method for class 'uncertainty_traceability' plot(x, ...)## S3 method for class 'uncertainty_traceability' plot(x, ...)
x |
An |
... |
Reserved arguments. |
A ggplot object, invisibly.
calibration <- uncertainty_type_b( "calibration", estimate = 100, uncertainty = 1, k = 2, distribution = "normal" ) transport <- uncertainty_type_b( "transport", estimate = 100, lower = 99.5, upper = 100.5, distribution = "rectangular" ) chain <- uncertainty_traceability( list(calibration = list(calibration), transport = list(transport)), value = 100 ) plot(chain)calibration <- uncertainty_type_b( "calibration", estimate = 100, uncertainty = 1, k = 2, distribution = "normal" ) transport <- uncertainty_type_b( "transport", estimate = 100, lower = 99.5, upper = 100.5, distribution = "rectangular" ) chain <- uncertainty_traceability( list(calibration = list(calibration), transport = list(transport)), value = 100 ) plot(chain)
Plot a Youden analysis
## S3 method for class 'youden_plot' plot(x, ...)## S3 method for class 'youden_plot' plot(x, ...)
x |
A |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly; the plot is drawn as a side
effect.
set.seed(42) d <- data.frame(m1 = rnorm(30, 100, 5), m2 = rnorm(30, 98, 5)) plot(youden_plot(d, "m1", "m2"))set.seed(42) d <- data.frame(m1 = rnorm(30, 100, 5), m2 = rnorm(30, 98, 5)) plot(youden_plot(d, "m1", "m2"))
For each sample (grouped by by), estimate variance components via
VCA::anovaVCA, compute SD / CV and their Satterthwaite confidence intervals.
precision(data, form, by = NULL, NegVC = FALSE, ...)precision(data, form, by = NULL, NegVC = FALSE, ...)
data |
Data frame containing the response variable and design factor columns. |
form |
Formula parsed by VCA (e.g. |
by |
Column name(s) for sample grouping, supports multiple columns. |
NegVC |
Allow negative variance components? Default |
... |
Additional arguments passed to |
Returns an object of class precision.
Use summary, profile, etc. to view results.
data(VCAdata1, package = "VCA") precision(VCAdata1, y ~ day/run, by = "sample") # More complex: deeply nested factors with more sample groups data(realData, package = "VCA") precision(realData, y ~ lot/calibration/day/run, by = "PID")data(VCAdata1, package = "VCA") precision(VCAdata1, y ~ day/run, by = "sample") # More complex: deeply nested factors with more sample groups data(realData, package = "VCA") precision(realData, y ~ lot/calibration/day/run, by = "PID")
Predict fitted values or inverse-predict (from y to x)
## S3 method for class 'fit_equation' predict( object, newdata = NULL, x = NULL, y = NULL, inverse = FALSE, interval = NULL, level = 0.95, ... )## S3 method for class 'fit_equation' predict( object, newdata = NULL, x = NULL, y = NULL, inverse = FALSE, interval = NULL, level = 0.95, ... )
object |
a fit_equation object |
newdata |
new data as a data.frame |
x |
x column name; NULL uses the original x column from the fit |
y |
y column name (inverse only); NULL uses the original y column |
inverse |
logical; if TRUE, solve for x given y values in newdata |
interval |
"confidence" or "prediction" |
level |
confidence level (default 0.95) |
... |
additional arguments passed to the underlying predict() |
data.frame with x, y, and (if requested) confidence/prediction interval columns
df4plc <- data.frame( conc = c(0.1, 0.3, 1, 3, 10, 30, 100), resp = c(12, 25, 48, 72, 88, 96, 99) ) f <- fit_equation("E07", df4plc, "conc", "resp") # Fitted values predict(f) # Confidence interval predict(f, interval = "confidence") # Prediction interval predict(f, interval = "prediction") # Inverse prediction: estimate x for y=50 predict(f, newdata = data.frame(resp = 50), inverse = TRUE)df4plc <- data.frame( conc = c(0.1, 0.3, 1, 3, 10, 30, 100), resp = c(12, 25, 48, 72, 88, 96, 99) ) f <- fit_equation("E07", df4plc, "conc", "resp") # Fitted values predict(f) # Confidence interval predict(f, interval = "confidence") # Prediction interval predict(f, interval = "prediction") # Inverse prediction: estimate x for y=50 predict(f, newdata = data.frame(resp = 50), inverse = TRUE)
Predict from an interference dose-response analysis
## S3 method for class 'interference_dose_response' predict( object, newdata = NULL, target = NULL, metric = c("result", "absolute", "percent"), stratum = NULL, ... )## S3 method for class 'interference_dose_response' predict( object, newdata = NULL, target = NULL, metric = c("result", "absolute", "percent"), stratum = NULL, ... )
object |
An |
newdata |
Numeric interferent concentrations for forward prediction. |
target |
Numeric effects for inverse prediction. Supply instead of
|
metric |
|
stratum |
Optional stratum key; by default all strata are processed. |
... |
Unused. |
A data frame of predictions or inverse interpolations.
d <- expand.grid(conc = c(0, 10, 20, 30, 40), rep = 1:5) d$result <- 100 + 0.5 * d$conc fit <- interference_dose_response(d, "result", "conc") predict(fit, newdata = c(5, 15), metric = "percent") predict(fit, target = 10, metric = "percent")d <- expand.grid(conc = c(0, 10, 20, 30, 40), rep = 1:5) d$result <- 100 + 0.5 * d$conc fit <- interference_dose_response(d, "result", "conc") predict(fit, newdata = c(5, 15), metric = "percent") predict(fit, target = 10, metric = "percent")
Predict values based on stored regression results.
## S3 method for class 'mcr' predict( object, newdata = NULL, reference = NULL, candidate = NULL, inverse = FALSE, interval = c("none", "confidence", "prediction", "both"), conf.level = 0.95, ci_method = c("auto", "analytic", "jackknife", "rank", "bootstrap_percentile", "bootstrap_standard"), bootstrap_replicates = 5000L, seed = NULL, ... )## S3 method for class 'mcr' predict( object, newdata = NULL, reference = NULL, candidate = NULL, inverse = FALSE, interval = c("none", "confidence", "prediction", "both"), conf.level = 0.95, ci_method = c("auto", "analytic", "jackknife", "rank", "bootstrap_percentile", "bootstrap_standard"), bootstrap_replicates = 5000L, seed = NULL, ... )
object |
mcr object (must call regression() first) |
newdata |
Data frame containing input values. If provided, reference or candidate names a column in it. |
reference |
Reference-method input for forward prediction. With newdata, a column name; otherwise a numeric vector. If NULL, uses the original reference values. |
candidate |
Candidate-method input for inverse prediction. With newdata, a column name; otherwise a numeric vector. If NULL, uses the original candidate values. |
inverse |
If FALSE, predict candidate from reference. If TRUE, algebraically predict reference from candidate. |
interval |
Interval type: "none" (default), "confidence", "prediction", "both". Only forward prediction (inverse=FALSE) supports intervals. |
conf.level |
Confidence level, default 0.95 |
ci_method |
Parameter-uncertainty method. |
bootstrap_replicates |
Number of paired Bootstrap resamples; at least 5000 when a Bootstrap method is used. |
seed |
Optional integer seed. |
... |
Additional arguments |
data.frame containing predicted values and (if requested) interval bounds
obj <- mcr(ivd_mcr_example, "sid", "test", "ref") obj <- regression(obj, method = "ols") predict(obj, reference = c(40, 50, 60)) predict(obj, reference = c(40, 50, 60), interval = "both") predict(obj, newdata = data.frame(xx = c(40, 50)), reference = "xx") predict(obj, inverse = TRUE) # Inverse prediction on original dataobj <- mcr(ivd_mcr_example, "sid", "test", "ref") obj <- regression(obj, method = "ols") predict(obj, reference = c(40, 50, 60)) predict(obj, reference = c(40, 50, 60), interval = "both") predict(obj, newdata = data.frame(xx = c(40, 50)), reference = "xx") predict(obj, inverse = TRUE) # Inverse prediction on original data
Predict positive-class probability for new data using a stored MLR model. Returns the input predictor columns together with predicted probability, standard error, confidence interval, and 0/1 classification.
## S3 method for class 'roc' predict(object, mlr = NULL, newdata = NULL, column_map = NULL, ...)## S3 method for class 'roc' predict(object, mlr = NULL, newdata = NULL, column_map = NULL, ...)
object |
roc object (must run mlr() first) |
mlr |
MLR model name (character). If only one MLR exists, defaults to it; if multiple exist, must specify. |
newdata |
data.frame of new observations. If NULL (default), uses the training data (complete cases) from the roc object. |
column_map |
Named character vector mapping newdata column names to training
column names, e.g. |
... |
Additional arguments passed to stats::predict.glm |
data.frame containing the predictor columns used in the model, plus:
pred_prob |
predicted probability of the positive class |
pred_se |
standard error of the predicted probability |
ci_lower |
lower bound of the confidence interval (probability scale) |
ci_upper |
upper bound of the confidence interval (probability scale) |
pred_class |
binary prediction (1 if pred_prob >= 0.5, 0 otherwise) |
df <- data.frame(sid = 1:100, x1 = c(rnorm(50, 10, 2), rnorm(50, 12, 2)), x2 = rnorm(100, 5, 1), ref = rep(c(0, 1), each = 50)) obj <- roc(df, cols = c("x1", "x2"), reference = "ref") obj <- auc(obj) obj <- mlr(obj) predict(obj) predict(obj, newdata = df[1:5, ]) ## column_map example: rename x1 to new_x1 in newdata new_df <- df[1:5, c("x2", "ref")] new_df$new_x1 <- df$x1[1:5] predict(obj, newdata = new_df, column_map = c(new_x1 = "x1", x2 = "x2"))df <- data.frame(sid = 1:100, x1 = c(rnorm(50, 10, 2), rnorm(50, 12, 2)), x2 = rnorm(100, 5, 1), ref = rep(c(0, 1), each = 50)) obj <- roc(df, cols = c("x1", "x2"), reference = "ref") obj <- auc(obj) obj <- mlr(obj) predict(obj) predict(obj, newdata = df[1:5, ]) ## column_map example: rename x1 to new_x1 in newdata new_df <- df[1:5, c("x2", "ref")] new_df$new_x1 <- df$x1[1:5] predict(obj, newdata = new_df, column_map = c(new_x1 = "x1", x2 = "x2"))
Print Arrhenius stability-analysis results
## S3 method for class 'arrhenius' print(x, ...)## S3 method for class 'arrhenius' print(x, ...)
x |
An |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly.
Print bottle ANOVA analysis results including descriptive statistics, ANOVA table, and assumption checks.
## S3 method for class 'bottle_anova' print(x, ...)## S3 method for class 'bottle_anova' print(x, ...)
x |
A |
... |
Other arguments (unused, for S3 generic signature) |
Invisibly returns x.
Print C5 and C95 estimates
## S3 method for class 'c5_c95' print(x, digits = 4L, ...)## S3 method for class 'c5_c95' print(x, digits = 4L, ...)
x |
A |
digits |
Number of digits shown. |
... |
Reserved arguments. |
Invisibly returns x.
set.seed(12) d <- data.frame(level = rep(1:5, each = 10), y = stats::rnorm(50, rep(seq(37, 43, length.out = 5), each = 10), 1)) print(c5_c95(d, "y", "level", cutoff = 40, model.no = 1))set.seed(12) d <- data.frame(level = rep(1:5, each = 10), y = stats::rnorm(50, rep(seq(37, 43, length.out = 5), each = 10), 1)) print(c5_c95(d, "y", "level", cutoff = 40, model.no = 1))
Print a commutability assessment
## S3 method for class 'commutability_result' print(x, ...)## S3 method for class 'commutability_result' print(x, ...)
x |
A commutability_result object. |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly.
Print a multiple-equation comparison
## S3 method for class 'compare_equation' print(x, ...)## S3 method for class 'compare_equation' print(x, ...)
x |
A |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly.
Print a fixed-cutpoint data split
## S3 method for class 'cutpoint_split' print(x, ...)## S3 method for class 'cutpoint_split' print(x, ...)
x |
A |
... |
Additional arguments (currently unused). |
The input object, invisibly.
S3 print method for describe_table
## S3 method for class 'describe_table' print(x, ...)## S3 method for class 'describe_table' print(x, ...)
x |
describe_table object |
... |
reserved arguments |
Invisible describe_table object
df <- data.frame( new = c("positive","positive","negative","negative","positive","negative"), gold = c("positive","negative","positive","negative","positive","positive"), age = c(45, 52, 38, 61, 47, 55), gender = c("M","F","F","M","M","F"), id = c("S001","S002","S003","S004","S005","S006") ) tab <- raw_to_table(df, "new", "gold", id = "id") tab <- describe(tab)df <- data.frame( new = c("positive","positive","negative","negative","positive","negative"), gold = c("positive","negative","positive","negative","positive","positive"), age = c(45, 52, 38, 61, 47, 55), gender = c("M","F","F","M","M","F"), id = c("S001","S002","S003","S004","S005","S006") ) tab <- raw_to_table(df, "new", "gold", id = "id") tab <- describe(tab)
diagnostics output (diagnostic performance metrics)Prints four-fold table frequencies, sensitivity, specificity, PPV, NPV, accuracy, likelihood ratios, etc.
## S3 method for class 'diagnostics' print(x, digits = 3, ...)## S3 method for class 'diagnostics' print(x, digits = 3, ...)
x |
|
digits |
Number of decimal places, default |
... |
reserved arguments |
Invisible diagnostics object
df <- data.frame( new = c("positive","positive","negative","negative","positive","negative"), gold = c("positive","negative","positive","negative","positive","positive"), age = c(45, 52, 38, 61, 47, 55), gender = c("M","F","F","M","M","F"), id = c("S001","S002","S003","S004","S005","S006") ) tab <- raw_to_table(df, "new", "gold", positive = "positive", id = "id") tab <- diagnostics(tab)df <- data.frame( new = c("positive","positive","negative","negative","positive","negative"), gold = c("positive","negative","positive","negative","positive","positive"), age = c(45, 52, 38, 61, 47, 55), gender = c("M","F","F","M","M","F"), id = c("S001","S002","S003","S004","S005","S006") ) tab <- raw_to_table(df, "new", "gold", positive = "positive", id = "id") tab <- diagnostics(tab)
Print dilution-recovery results
## S3 method for class 'dilution_recovery' print(x, ...)## S3 method for class 'dilution_recovery' print(x, ...)
x |
A |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly.
Print a categorical data split
## S3 method for class 'factor_split' print(x, ...)## S3 method for class 'factor_split' print(x, ...)
x |
A |
... |
Additional arguments (currently unused). |
The input object, invisibly.
Print an equation fit
## S3 method for class 'fit_equation' print(x, ...)## S3 method for class 'fit_equation' print(x, ...)
x |
A |
... |
Additional arguments (currently unused). |
x, invisibly.
fourfold_table object as a fourfold tablePrints data source, total sample size, variable names, fourfold table (with margins), and analysis status.
## S3 method for class 'fourfold_table' print(x, margin = TRUE, ...)## S3 method for class 'fourfold_table' print(x, margin = TRUE, ...)
x |
|
margin |
Whether to display margins, default |
... |
reserved arguments |
Invisible fourfold_table object
df <- data.frame( new = c("positive","positive","negative","negative","positive","negative"), gold = c("positive","negative","positive","negative","positive","positive"), age = c(45, 52, 38, 61, 47, 55), gender = c("M","F","F","M","M","F"), id = c("S001","S002","S003","S004","S005","S006") ) tab <- raw_to_table(df, "new", "gold", id = "id") print(tab)df <- data.frame( new = c("positive","positive","negative","negative","positive","negative"), gold = c("positive","negative","positive","negative","positive","positive"), age = c(45, 52, 38, 61, 47, 55), gender = c("M","F","F","M","M","F"), id = c("S001","S002","S003","S004","S005","S006") ) tab <- raw_to_table(df, "new", "gold", id = "id") print(tab)
Print high-dose hook-effect results
## S3 method for class 'hook_effect' print(x, ...)## S3 method for class 'hook_effect' print(x, ...)
x |
A |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly.
Print interference dose-response results
## S3 method for class 'interference_dose_response' print(x, ...)## S3 method for class 'interference_dose_response' print(x, ...)
x |
An |
... |
Unused. |
x, invisibly.
d <- expand.grid(conc = c(0, 10, 20), rep = 1:5) d$result <- 100 + 0.5 * d$conc print(interference_dose_response(d, "result", "conc"))d <- expand.grid(conc = c(0, 10, 20), rep = 1:5) d$result <- 100 + 0.5 * d$conc print(interference_dose_response(d, "result", "conc"))
Print paired interference estimates
## S3 method for class 'interference_paired' print(x, ...)## S3 method for class 'interference_paired' print(x, ...)
x |
An |
... |
Unused. |
x, invisibly.
d <- data.frame(group = rep(c("control", "test"), each = 5), result = c(10, 10.1, 9.9, 10.2, 9.8, 11, 11.1, 10.9, 11.2, 10.8)) print(interference_paired(d, "result", "ep07", condition = "group"))d <- data.frame(group = rep(c("control", "test"), each = 5), result = c(10, 10.1, 9.9, 10.2, 9.8, 11, 11.1, 10.9, 11.2, 10.8)) print(interference_paired(d, "result", "ep07", condition = "group"))
Print patient-specimen interference results
## S3 method for class 'interference_patient' print(x, ...)## S3 method for class 'interference_patient' print(x, ...)
x |
An |
... |
Unused. |
x, invisibly.
d <- expand.grid(id = paste0("S", 1:6), method = c("test", "ref"), rep = 1:2) d$group <- ifelse(as.integer(sub("S", "", d$id)) <= 3, "control", "selected") d$result <- 10 + as.integer(sub("S", "", d$id)) + (d$method == "test") print(interference_patient(d, "id", "group", "method", "result", "selected", "control", "test", "ref"))d <- expand.grid(id = paste0("S", 1:6), method = c("test", "ref"), rep = 1:2) d$group <- ifelse(as.integer(sub("S", "", d$id)) <= 3, "control", "selected") d$result <- 10 + as.integer(sub("S", "", d$id)) + (d$method == "test") print(interference_patient(d, "id", "group", "method", "result", "selected", "control", "test", "ref"))
Print EP07 replicate-count results
## S3 method for class 'interference_replicates' print(x, ...)## S3 method for class 'interference_replicates' print(x, ...)
x |
An |
... |
Unused. |
x, invisibly.
print(interference_replicates(5, 7))print(interference_replicates(5, 7))
kappa_table outputPrints Cohen's Kappa / PABAK coefficient, standard error, confidence interval, and agreement rates.
## S3 method for class 'kappa_table' print(x, digits = 4, ...)## S3 method for class 'kappa_table' print(x, digits = 4, ...)
x |
|
digits |
Number of decimal places, default |
... |
reserved arguments |
Invisible kappa_table object
tab <- counts_to_table(tp = 85, fp = 3, tn = 90, fn = 2, candidate = "new method", reference = "gold standard") tab <- kappa(tab)tab <- counts_to_table(tp = 85, fp = 3, tn = 90, fn = 2, candidate = "new method", reference = "gold standard") tab <- kappa(tab)
Print a linearity analysis
## S3 method for class 'linearity' print(x, ...)## S3 method for class 'linearity' print(x, ...)
x |
A |
... |
Reserved arguments. |
The unchanged x, invisibly.
mcnemar_table outputPrints McNemar test results, including discordant pair counts, test statistic, and p-value.
## S3 method for class 'mcnemar_table' print(x, ...)## S3 method for class 'mcnemar_table' print(x, ...)
x |
|
... |
reserved arguments |
Invisible mcnemar_table object
tab <- counts_to_table(tp = 45, fp = 12, tn = 80, fn = 5, candidate = "new method", reference = "gold standard") tab <- mcnemar(tab)tab <- counts_to_table(tp = 45, fp = 12, tn = 80, fn = 5, candidate = "new method", reference = "gold standard") tab <- mcnemar(tab)
Print data overview and analysis slot status based on $print slot.
## S3 method for class 'mcr' print(x, ...)## S3 method for class 'mcr' print(x, ...)
x |
|
... |
Additional arguments |
Invisible mcr object
df <- data.frame(sid = 1:30, test = rnorm(30, 50, 10), ref = rnorm(30, 50, 10)) obj <- mcr(df, "sid", "test", "ref") print(obj)df <- data.frame(sid = 1:30, test = rnorm(30, 50, 10), ref = rnorm(30, 50, 10)) obj <- mcr(df, "sid", "test", "ref") print(obj)
Print method for bias results
## S3 method for class 'mcr_bias' print(x, ...)## S3 method for class 'mcr_bias' print(x, ...)
x |
mcr_bias object |
... |
additional arguments |
The unchanged mcr_bias data frame, invisibly.
Print method for Bland-Altman results
## S3 method for class 'mcr_bland_altman' print(x, ...)## S3 method for class 'mcr_bland_altman' print(x, ...)
x |
mcr_bland_altman object |
... |
additional arguments |
The unchanged mcr_bland_altman object, invisibly.
Print method for correlation results
## S3 method for class 'mcr_correlation' print(x, ...)## S3 method for class 'mcr_correlation' print(x, ...)
x |
mcr_correlation object |
... |
additional arguments |
The unchanged mcr_correlation object, invisibly.
Print method for describe results
## S3 method for class 'mcr_describe' print(x, digits = NULL, ...)## S3 method for class 'mcr_describe' print(x, digits = NULL, ...)
x |
mcr_describe object |
digits |
Number of decimal places, default 4 |
... |
additional arguments |
The unchanged mcr_describe object, invisibly.
Print method for outlier results
## S3 method for class 'mcr_outlier' print(x, ...)## S3 method for class 'mcr_outlier' print(x, ...)
x |
mcr_outlier object |
... |
additional arguments |
The unchanged mcr_outlier object, invisibly.
Print method for regression results
## S3 method for class 'mcr_regression' print(x, ...)## S3 method for class 'mcr_regression' print(x, ...)
x |
mcr_regression object |
... |
additional arguments |
The unchanged mcr_regression object, invisibly.
Print mean kinetic temperature results
## S3 method for class 'mkt' print(x, ...)## S3 method for class 'mkt' print(x, ...)
x |
A |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly.
Print a normality test result
## S3 method for class 'normal_test' print(x, ...)## S3 method for class 'normal_test' print(x, ...)
x |
A |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly.
Print an outlier detection result
## S3 method for class 'outliers_test' print(x, ...)## S3 method for class 'outliers_test' print(x, ...)
x |
An |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly.
Print the data overview of a precision object (data class, total rows, formula,
grouping variables, sample count, factor levels, balance warnings) and the analysis
slot status ([x] / [ ]).
## S3 method for class 'precision' print(x, ...)## S3 method for class 'precision' print(x, ...)
x |
|
... |
Reserved arguments |
Invisible precision object
Prints confidence interval tables for SD and \ sample, component, estimate, lower, upper.
## S3 method for class 'precision_ci' print(x, ...)## S3 method for class 'precision_ci' print(x, ...)
x |
|
... |
Reserved arguments |
Invisibly returns x.
Prints the selected normality test result per sample, including the actual method, sample size, statistic name, statistic, and p-value.
## S3 method for class 'precision_normal' print(x, ...)## S3 method for class 'precision_normal' print(x, ...)
x |
|
... |
Reserved arguments |
Invisibly returns x.
Prints the outlier detection method, count of outliers found, and the detail table (row, sample, value, statistic, critical value).
## S3 method for class 'precision_outlier' print(x, ...)## S3 method for class 'precision_outlier' print(x, ...)
x |
|
... |
Reserved arguments |
Invisibly returns x.
Prints the best Sadler model formula, AIC, and R-squared for each variance component.
## S3 method for class 'precision_profile' print(x, ...)## S3 method for class 'precision_profile' print(x, ...)
x |
|
... |
Reserved arguments |
Invisibly returns x.
Prints the variance component summary table with columns: sample, component, VC (variance component), \
## S3 method for class 'precision_vc' print(x, ...)## S3 method for class 'precision_vc' print(x, ...)
x |
|
... |
Reserved arguments |
Invisibly returns x.
Print a Levey-Jennings QC chart analysis
## S3 method for class 'qc_chart' print(x, ...)## S3 method for class 'qc_chart' print(x, ...)
x |
A |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly.
Print reference-material bias results
## S3 method for class 'reference_bias' print(x, ...)## S3 method for class 'reference_bias' print(x, ...)
x |
A |
... |
Reserved arguments. |
x, invisibly.
d <- data.frame(result = c(9.8, 10.0, 10.1, 9.9, 10.2, 10.0)) print(reference_bias(d, "result", reference = 10, reference_uncertainty = 0.2))d <- data.frame(result = c(9.8, 10.0, 10.1, 9.9, 10.2, 10.0)) print(reference_bias(d, "result", reference = 10, reference_uncertainty = 0.2))
Print reference interval analysis results
## S3 method for class 'reference_interval' print(x, ...)## S3 method for class 'reference_interval' print(x, ...)
x |
A "reference_interval" object. |
... |
Additional arguments (reserved for generic). |
The unchanged reference_interval object, invisibly.
Print a ROC analysis object
## S3 method for class 'roc' print(x, ...)## S3 method for class 'roc' print(x, ...)
x |
A |
... |
Additional arguments (currently unused). |
x, invisibly.
Print a paired AUC comparison
## S3 method for class 'roc_auc_comparison' print(x, ...)## S3 method for class 'roc_auc_comparison' print(x, ...)
x |
A |
... |
Additional arguments (currently unused). |
The input object, invisibly.
Print method for roc AUC table
## S3 method for class 'roc_auc_table' print(x, ...)## S3 method for class 'roc_auc_table' print(x, ...)
x |
roc_auc_table object (data.frame) |
... |
additional arguments |
The unchanged roc_auc_table data frame, invisibly.
Print method for roc cutoff table
## S3 method for class 'roc_cutoff_table' print(x, ...)## S3 method for class 'roc_cutoff_table' print(x, ...)
x |
roc_cutoff_table object (data.frame) |
... |
additional arguments |
The unchanged roc_cutoff_table data frame, invisibly.
Print method for roc describe results
## S3 method for class 'roc_describe' print(x, digits = NULL, ...)## S3 method for class 'roc_describe' print(x, digits = NULL, ...)
x |
roc_describe object |
digits |
number of decimal places, default 4 |
... |
additional arguments |
The unchanged roc_describe object, invisibly.
Print a multivariate ROC model
## S3 method for class 'roc_mlr' print(x, ...)## S3 method for class 'roc_mlr' print(x, ...)
x |
A |
... |
Additional arguments (currently unused). |
x, invisibly.
Print Bland-Altman sample-size results
## S3 method for class 'sample_size_bland_altman' print(x, ...)## S3 method for class 'sample_size_bland_altman' print(x, ...)
x |
A |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly.
Print single-proportion target-value sample-size results
## S3 method for class 'sample_size_proportion' print(x, ...)## S3 method for class 'sample_size_proportion' print(x, ...)
x |
A |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly.
Print single-proportion confidence-interval sample-size results
## S3 method for class 'sample_size_proportion_ci' print(x, ...)## S3 method for class 'sample_size_proportion_ci' print(x, ...)
x |
A |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly.
Print an analytical-sensitivity analysis result
## S3 method for class 'sensitivity' print(x, ...)## S3 method for class 'sensitivity' print(x, ...)
x |
A |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly.
Print an analytical-sensitivity study design
## S3 method for class 'sensitivity_design' print(x, ...)## S3 method for class 'sensitivity_design' print(x, ...)
x |
A |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly.
Print spike-concentration calculations
## S3 method for class 'spike_concentration' print(x, ...)## S3 method for class 'spike_concentration' print(x, ...)
x |
A |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly.
Print spike-recovery results
## S3 method for class 'spike_recovery' print(x, ...)## S3 method for class 'spike_recovery' print(x, ...)
x |
A |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly.
Print stability-bias results
## S3 method for class 'stability_bias' print(x, ...)## S3 method for class 'stability_bias' print(x, ...)
x |
A |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly.
Print a stability study time-point plan
## S3 method for class 'stability_plan' print(x, ...)## S3 method for class 'stability_plan' print(x, ...)
x |
A |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly.
Print stability-regression results
## S3 method for class 'stability_regression' print(x, ...)## S3 method for class 'stability_regression' print(x, ...)
x |
A |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly.
Print stability limit-time predictions
## S3 method for class 'stability_time' print(x, ...)## S3 method for class 'stability_time' print(x, ...)
x |
A |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly.
Print Tukey HSD post-hoc test results including pairwise comparison table, significance markers, and compact letter display.
## S3 method for class 'tukey' print(x, ...)## S3 method for class 'tukey' print(x, ...)
x |
A |
... |
Other arguments (unused, for S3 generic signature) |
Invisibly returns x.
Print a combined uncertainty budget
## S3 method for class 'uncertainty_budget' print(x, ...)## S3 method for class 'uncertainty_budget' print(x, ...)
x |
An uncertainty_budget object. |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly.
Print characterization uncertainty results
## S3 method for class 'uncertainty_characterization' print(x, ...)## S3 method for class 'uncertainty_characterization' print(x, ...)
x |
An uncertainty_characterization object. |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly.
Print an uncertainty component
## S3 method for class 'uncertainty_component' print(x, ...)## S3 method for class 'uncertainty_component' print(x, ...)
x |
An uncertainty_component object. |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly.
Print between-unit homogeneity uncertainty results
## S3 method for class 'uncertainty_homogeneity' print(x, ...)## S3 method for class 'uncertainty_homogeneity' print(x, ...)
x |
An uncertainty_homogeneity object. |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly.
Print IQC uncertainty results
## S3 method for class 'uncertainty_iqc' print(x, ...)## S3 method for class 'uncertainty_iqc' print(x, ...)
x |
An uncertainty_iqc object. |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly.
Print propagated uncertainty results
## S3 method for class 'uncertainty_propagation' print(x, ...)## S3 method for class 'uncertainty_propagation' print(x, ...)
x |
An uncertainty_propagation object. |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly.
Print stability uncertainty results
## S3 method for class 'uncertainty_stability' print(x, ...)## S3 method for class 'uncertainty_stability' print(x, ...)
x |
An uncertainty_stability object. |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly.
Print traceability-chain uncertainty results
## S3 method for class 'uncertainty_traceability' print(x, ...)## S3 method for class 'uncertainty_traceability' print(x, ...)
x |
An uncertainty_traceability object. |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly.
Print a Youden plot analysis
## S3 method for class 'youden_plot' print(x, ...)## S3 method for class 'youden_plot' print(x, ...)
x |
A |
... |
Reserved for the S3 generic. |
The unchanged x, invisibly.
Fit precision (SD) vs. mean across samples using the Sadler model selection algorithm
(10 candidate models) based on VFP::fit_vfp().
## S3 method for class 'precision' profile(object, model.no = 1:10, ...)## S3 method for class 'precision' profile(object, model.no = 1:10, ...)
object |
|
model.no |
Vector of candidate model numbers, default |
... |
Additional arguments passed to |
Updated precision object with results stored in $profile
data(VCAdata1, package = "VCA") obj <- precision(VCAdata1, y ~ day/run, by = "sample") obj <- variance(obj) obj <- profile(obj, model.no = 1)data(VCAdata1, package = "VCA") obj <- precision(VCAdata1, y ~ day/run, by = "sample") obj <- variance(obj) obj <- profile(obj, model.no = 1)
Draws a Levey-Jennings QC chart and detects out-of-control points based on selected Westgard rules. If target mean and SD are not provided, they are estimated from the data.
qc_chart( data, value, rules = "1-2s,1-3s,2-2s,R-4s,4-1s,10x", mean = NULL, sd = NULL, group = NULL, run = NULL )qc_chart( data, value, rules = "1-2s,1-3s,2-2s,R-4s,4-1s,10x", mean = NULL, sd = NULL, group = NULL, run = NULL )
data |
A data frame. |
value |
Column name (numeric) containing measured values. |
rules |
Comma-separated rule names, e.g. "1-2s,1-3s,10x". Rule names must match those printed by list_westgard(). |
mean |
Target mean; NULL to estimate from the selected data column. |
sd |
Target SD; NULL to estimate from the selected data column. |
group |
Optional grouping column name (e.g. QC lot), used for faceted plots. |
run |
Run-order column name (optional, default 1:n). |
An object of class "qc_chart" with violation results
and plot data. Use print() to show summary and plot()
to draw the Levey-Jennings chart.
set.seed(42) df <- data.frame( run = 1:30, value = c(rnorm(27, 100, 5), 108, 115, 85) ) res <- qc_chart(df, "value", rules = "1-2s,1-3s,10x") print(res) plot(res)set.seed(42) df <- data.frame( run = 1:30, value = c(rnorm(27, 100, 5), 108, 115, 85) ) res <- qc_chart(df, "value", rules = "1-2s,1-3s,10x") print(res) plot(res)
Core function: raw data -> frequency fourfold table (silent construction)
raw_to_table( data, candidate, reference, id = NULL, na.rm = TRUE, positive = NULL )raw_to_table( data, candidate, reference, id = NULL, na.rm = TRUE, positive = NULL )
data |
Data frame, one observation per row |
candidate |
Candidate method variable name (character), e.g. "method_new" |
reference |
Reference method variable name (character), e.g. "method_standard" |
id |
ID variable name (character), optional, used for duplicate detection in describe |
na.rm |
Whether to remove NA, default TRUE |
positive |
Specify the positive label (character); if non-NULL, levels will be uniformly mapped to positive/negative. If NULL, the last sorted level is treated as positive. |
A fourfold_table object (list with S3 class "fourfold_table"), containing: - $freq_raw Raw frequencies (long format) - $table Fourfold matrix (with margins) - $n Total sample size - $print Print slot (descriptive metadata) - $candidate_levels Levels of the candidate method - $reference_levels Levels of the reference method Use print() directly to display the fourfold table.
df <- data.frame( new = c("positive","positive","negative","negative","positive","negative"), gold = c("positive","negative","positive","negative","positive","positive"), age = c(45, 52, 38, 61, 47, 55), gender = c("M","F","F","M","M","F"), id = c("S001","S002","S003","S004","S005","S006") ) result <- raw_to_table(df, "new", "gold", id = "id")df <- data.frame( new = c("positive","positive","negative","negative","positive","negative"), gold = c("positive","negative","positive","negative","positive","positive"), age = c(45, 52, 38, 61, 47, 55), gender = c("M","F","F","M","M","F"), id = c("S001","S002","S003","S004","S005","S006") ) result <- raw_to_table(df, "new", "gold", id = "id")
Calculates measurement bias and its interval according to Section 5.3 of
YY/T 1789.2-2021. For each reference-material level, the uncertainty of the
measured mean is calculated as s / sqrt(n) and expanded by k.
This expanded uncertainty is then combined with the reference-material
uncertainty. The function reports results only and applies no acceptance
criterion.
reference_bias( data, result, reference, reference_uncertainty, level = NULL, k = 2 )reference_bias( data, result, reference, reference_uncertainty, level = NULL, k = 2 )
data |
A data frame containing replicate measurement results. |
result |
Name of the numeric measurement-result column. |
reference |
Reference-material assigned value. Supply a finite scalar,
a numeric vector with one value per row or level, or the name of a numeric
column in |
reference_uncertainty |
Expanded uncertainty of the reference material,
at the same coverage level as the uncertainty calculated with |
level |
Optional name of the reference-material level column. When omitted, all rows are treated as one level. |
k |
Positive coverage factor used to expand the standard uncertainty of
the measured mean. The standard's example uses |
An object of class "reference_bias". Its result
component contains the sample size, mean, standard deviation, uncertainty,
bias, relative bias, and interval for each reference-material level.
YY/T 1789.2-2021, Section 5.3 and Appendix A.
reference_data <- data.frame( level = rep(c("low", "high"), each = 6), result = c(9.8, 10.1, 10.0, 9.9, 10.2, 10.0, 19.7, 20.1, 20.0, 19.9, 20.2, 20.1) ) bias_result <- reference_bias( reference_data, result = "result", reference = c(10, 20), reference_uncertainty = c(0.2, 0.3), level = "level" ) bias_result$resultreference_data <- data.frame( level = rep(c("low", "high"), each = 6), result = c(9.8, 10.1, 10.0, 9.9, 10.2, 10.0, 19.7, 20.1, 20.0, 19.9, 20.2, 20.1) ) bias_result <- reference_bias( reference_data, result = "result", reference = c(10, 20), reference_uncertainty = c(0.2, 0.3), level = "level" ) bias_result$result
Calculates reference intervals using the CLSI EP28-A3c simple nonparametric or biweight procedures, a normal/log-normal parametric procedure, or the retained R type-6 and Huber procedures.
reference_interval( data, col, interval = 0.95, ci = 0.95, method = "nonparametric", id = NULL, bootstrap_replicates = 1999L, seed = NULL )reference_interval( data, col, interval = 0.95, ci = 0.95, method = "nonparametric", id = NULL, bootstrap_replicates = 1999L, seed = NULL )
data |
A data frame. |
col |
A single character string naming the numeric result column. |
interval |
Central reference interval coverage in |
ci |
Confidence level for each reference-limit interval in |
method |
One or more of |
id |
Optional single character string naming an ID column used only to report duplicate IDs. |
bootstrap_replicates |
Number of percentile-bootstrap resamples for
|
seed |
Optional integer seed for biweight and Huber bootstrap resampling. The caller's random-number state is preserved. |
method = "nonparametric" uses ranks p * (n + 1), linear interpolation,
and exact binomial order-statistic confidence intervals. method = "biweight" implements the EP28 Appendix B biweight location and scale
calculation and percentile bootstrap confidence intervals. method = "type6" retains the previous R type-6 quantiles with normal-approximation
rank intervals. method = "huber" retains the previous Huber M-estimator.
An object of class reference_interval. Selected results are stored
in correspondingly named elements: nonparametric, biweight, type6,
parametric, and huber. Data-quality counts and cleaned values are
also retained.
Clinical and Laboratory Standards Institute. Defining, Establishing, and Verifying Reference Intervals in the Clinical Laboratory; Approved Guideline—Third Edition. CLSI document EP28-A3c. Wayne, PA: CLSI; 2010.
set.seed(17) d <- data.frame(id = seq_len(150), value = rnorm(150, 100, 15)) reference_interval(d, "value", id = "id") reference_interval(d, "value", method = c("nonparametric", "parametric")) reference_interval(d, "value", method = "all", bootstrap_replicates = 199, seed = 28)set.seed(17) d <- data.frame(id = seq_len(150), value = rnorm(150, 100, 15)) reference_interval(d, "value", id = "id") reference_interval(d, "value", method = c("nonparametric", "parametric")) reference_interval(d, "value", method = "all", bootstrap_replicates = 199, seed = 28)
Perform regression analysis with the reference/comparative method on the X-axis and the candidate/test method on the Y-axis. Supports five methods: Ordinary Least Squares (OLS), Weighted Least Squares (WLS), Deming regression, Weighted Deming regression, and Passing-Bablok regression.
## S3 method for class 'mcr' regression( x, method = c("ols", "wls", "deming", "wdeming", "pb"), conf.level = 0.95, lambda = 1, weights = NULL, variance_models = NULL, profile_components = c(reference = "total", candidate = "total"), ci_method = c("auto", "analytic", "jackknife", "rank", "bootstrap_percentile", "bootstrap_standard"), bootstrap_replicates = 5000L, seed = NULL, mdl = NULL, weight_iterations = 4L, epsilon = NULL, ... )## S3 method for class 'mcr' regression( x, method = c("ols", "wls", "deming", "wdeming", "pb"), conf.level = 0.95, lambda = 1, weights = NULL, variance_models = NULL, profile_components = c(reference = "total", candidate = "total"), ci_method = c("auto", "analytic", "jackknife", "rank", "bootstrap_percentile", "bootstrap_standard"), bootstrap_replicates = 5000L, seed = NULL, mdl = NULL, weight_iterations = 4L, epsilon = NULL, ... )
x |
mcr object |
method |
Regression method: "ols" (default), "wls", "deming", "wdeming", "pb" |
conf.level |
Confidence level, default 0.95 |
lambda |
Variance ratio for Deming regression (candidate/Y variance
divided by reference/X variance), or |
weights |
Weights specification, default NULL (unweighted).
Character string for built-in modes: "equal", "1/y", "1/y^2", "1/x", "1/x^2",
"constant_cv", "precision_profile", "residual", or a column name in data
containing non-negative weights. Constant-CV means exactly |
variance_models |
For precision-profile Deming, a two-element list
identifying |
profile_components |
Precision-profile components for reference and
candidate methods; both default to |
ci_method |
Regression-parameter interval method. |
bootstrap_replicates |
Number of paired Bootstrap resamples; at least 5000 when a Bootstrap interval is requested. |
seed |
Optional integer seed. The caller's random-number state is restored after a seeded analysis. |
mdl |
Optional medical decision levels for which bias Bootstrap draws are retained with the regression result. |
weight_iterations |
Number of residual-weight updates when
|
epsilon |
Convergence tolerance for constant-CV or precision-profile Deming. NULL uses the underlying algorithm's default. |
... |
Additional arguments passed to lm (OLS/WLS only) |
Updated mcr object (invisible), results stored in $regression
obj <- mcr(ivd_mcr_example, "sid", "test", "ref") regression(obj, method = "ols") regression(obj, method = "deming")obj <- mcr(ivd_mcr_example, "sid", "test", "ref") regression(obj, method = "ols") regression(obj, method = "deming")
Groups data by x, computes mean, SD, and sample size for each group.
When weights is specified, returns an additional weight column.
Summary metadata (call, weighting method, column names) is stored as
attributes for downstream reference.
replicate_to_mean(data, x, y, weights = NULL, na.rm = TRUE)replicate_to_mean(data, x, y, weights = NULL, na.rm = TRUE)
data |
a data frame |
x |
x column name (grouping variable) |
y |
One or more y column names (response variables). A single
response retains the historical |
weights |
weighting method: NULL / "n" / "1/sd" / "1/sd^2" NULL – summary only, no weight column "n" – w = number of replicates "1/sd" – w = 1/sd(y) "1/sd^2" – w = 1/var(y) (inverse-variance weighting) |
na.rm |
remove NA? (default TRUE) |
A data.frame with columns:
x |
grouping variable |
y_mean, y_sd, y_n
|
Historical names used for one response. |
\if{html}{\out{<name>}}_mean, \if{html}{\out{<name>}}_sd, \if{html}{\out{<name>}}_n
|
Names used for each response when two or more response columns are supplied. |
weight |
(only when weights is specified) weight values |
Attributes: call, weights (method name), x_col, y_col
# Basic summary df <- data.frame( conc = rep(c(1, 2, 5, 10), each = 3), resp = c(3.1, 3.2, 2.9, 5.8, 6.1, 5.9, 14.2, 14.5, 14.0, 28.1, 27.9, 28.3) ) rep <- replicate_to_mean(df, "conc", "resp") rep # Inverse-variance weighting rep_w <- replicate_to_mean(df, "conc", "resp", weights = "1/sd^2") rep_w# Basic summary df <- data.frame( conc = rep(c(1, 2, 5, 10), each = 3), resp = c(3.1, 3.2, 2.9, 5.8, 6.1, 5.9, 14.2, 14.5, 14.0, 28.1, 27.9, 28.3) ) rep <- replicate_to_mean(df, "conc", "resp") rep # Inverse-variance weighting rep_w <- replicate_to_mean(df, "conc", "resp", weights = "1/sd^2") rep_w
Generate an EP05 precision summary table
## S3 method for class 'precision' report( x, day, run = NULL, site = NULL, table = c("simple", "detailed", "CI"), digits = 4L, ... )## S3 method for class 'precision' report( x, day, run = NULL, site = NULL, table = c("simple", "detailed", "CI"), digits = 4L, ... )
x |
A precision object after |
day |
Name of the day (or equivalent) design variable. |
run |
Name of the run variable, when present. |
site |
Name of the site variable for a multisite design. |
table |
One of |
digits |
Number of decimal places. |
... |
Reserved for future extensions. |
Interaction terms are matched independently of the textual order
of their factors. For a multisite design, within-laboratory precision is
formed from the within-site components (for example, site:day + error),
whereas reproducibility includes the between-site component. With
table = "CI", confidence intervals for combined components use the
variance-component covariance matrix and a Satterthwaite approximation.
A data.frame containing the requested report table.
if (requireNamespace("VCA", quietly = TRUE)) { data(VCAdata1, package = "VCA") p <- precision(VCAdata1, y ~ day/run, by = "sample") p <- variance(p) report(p, day = "day", run = "run", table = "simple") }if (requireNamespace("VCA", quietly = TRUE)) { data(VCAdata1, package = "VCA") p <- precision(VCAdata1, y ~ day/run, by = "sample") p <- variance(p) report(p, day = "day", run = "run", table = "simple") }
Extract residuals from an equation fit
## S3 method for class 'fit_equation' residuals(object, ...)## S3 method for class 'fit_equation' residuals(object, ...)
object |
A |
... |
Additional arguments passed to the fitted model. |
A numeric vector of residuals.
df <- data.frame(x = 1:5, y = c(2.1, 4.0, 6.2, 7.9, 10.1)) f <- fit_equation("E01", df, "x", "y") residuals(f)df <- data.frame(x = 1:5, y = c(2.1, 4.0, 6.2, 7.9, 10.1)) f <- fit_equation("E01", df, "x", "y") residuals(f)
Create an ROC analysis object.
roc(data, cols, reference, id = NULL, positive = NULL)roc(data, cols, reference, id = NULL, positive = NULL)
data |
data frame |
cols |
evaluation column names (character vector, quantitative, can be multiple) |
reference |
reference column name (character, single column). Must be binary 0/1,
a factor with 2 levels, or a character vector with 2 unique values.
If the original reference is quantitative, use |
id |
ID column name (optional, for duplicate detection) |
positive |
specify the positive level of reference (for factor/character) |
Supports multiple evaluation columns (quantitative) and a single reference column (binary 0/1, factor, or character with two levels). Automatically detects direction, reports missing values and ID duplicates.
Returns an S3 object of class "roc"
df <- data.frame( sid = 1:100, x1 = c(rnorm(50, 10, 2), rnorm(50, 12, 2)), ref = rep(c(0, 1), each = 50), age = 1:100, sex = rep(c("F", "M"), each = 50) ) obj <- roc(df, cols = "x1", reference = "ref", id = "sid") print(obj)df <- data.frame( sid = 1:100, x1 = c(rnorm(50, 10, 2), rnorm(50, 12, 2)), ref = rep(c(0, 1), each = 50), age = 1:100, sex = rep(c("F", "M"), each = 50) ) obj <- roc(df, cols = "x1", reference = "ref", id = "sid") print(obj)
Calculates the minimum number of measurement pairs required to attain a target power using the noncentral-t approximation of Lu et al. (2016).
sample_size_bland_altman( power = 0.8, mu, sd, delta, conf.level = 0.95, agree.level = 0.95, method = "lu", n.min = 3L, n.max = 1e+05 )sample_size_bland_altman( power = 0.8, mu, sd, delta, conf.level = 0.95, agree.level = 0.95, method = "lu", n.min = 3L, n.max = 1e+05 )
power |
Target power in |
mu |
Anticipated mean difference between the two measurement methods. |
sd |
Anticipated standard deviation of the differences. |
delta |
Positive symmetric clinical agreement limit. |
conf.level |
Confidence level for the confidence intervals around the limits of agreement. Default 0.95. |
agree.level |
Central proportion defining the limits of agreement. Default 0.95. |
method |
Calculation method. Currently only |
n.min |
Minimum sample size considered. Default 3. |
n.max |
Maximum sample size considered. Default 100000. |
An object of class sample_size_bland_altman. The required
sample size is available as x$n; the requested and attained powers
are available as x$target_power and x$achieved_power.
Lu MJ, Zhong WH, Liu YX, Miao HZ, Li YC, Ji MH (2016). Sample size for assessing agreement between two methods of measurement by Bland-Altman method. International Journal of Biostatistics, 12(2). doi:10.1515/ijb-2015-0039
sample_size_bland_altman( power = 0.80, mu = 0.2, sd = 1, delta = 2.5 )sample_size_bland_altman( power = 0.80, mu = 0.2, sd = 1, delta = 2.5 )
Calculates the minimum sample size required to test a single proportion against a target value. The test statistic and the power-calculation method are selected independently. Regardless of the planning method, the returned result includes the exact binomial Type I error and power of the resulting discrete rejection region.
sample_size_proportion( p0, p1, alpha = 0.05, power = 0.8, alternative = c("greater", "less", "two.sided"), test = c("exact", "score", "score-cc", "wald", "wald-cc", "agresti-coull", "jeffreys"), power_method = c("binomial", "normal"), n.max = 1e+06 )sample_size_proportion( p0, p1, alpha = 0.05, power = 0.8, alternative = c("greater", "less", "two.sided"), test = c("exact", "score", "score-cc", "wald", "wald-cc", "agresti-coull", "jeffreys"), power_method = c("binomial", "normal"), n.max = 1e+06 )
p0 |
Null or target proportion in |
p1 |
Anticipated proportion under the alternative in |
alpha |
Target significance level in |
power |
Target power in |
alternative |
One of |
test |
Rejection-region method. One of |
power_method |
Power calculation used to select the sample size:
|
n.max |
Maximum sample size considered. Default 1000000. |
test = "score", power_method = "normal" uses the null variance for
the alpha term and the alternative variance for the beta term. This is the
normal-approximation procedure used by the CMDE target-value formula.
With an infinite population, test = "exact" and test = "score" have
the same normal-approximation formula, matching PASS. The test choice still
determines the discrete rejection region used for the reported actual alpha
and achieved power.
An object of class sample_size_proportion. The required
sample size is available as x$n. The object also contains target
and planning power, exact achieved power, actual alpha, and critical
success counts.
# Exact binomial design sample_size_proportion( p0 = 0.2, p1 = 0.35, alpha = 0.05, power = 0.8, alternative = "greater" ) # CMDE continuous normal approximation sample_size_proportion( p0 = 0.85, p1 = 0.90, alpha = 0.05, power = 0.8, alternative = "two.sided", test = "score", power_method = "normal" )# Exact binomial design sample_size_proportion( p0 = 0.2, p1 = 0.35, alpha = 0.05, power = 0.8, alternative = "greater" ) # CMDE continuous normal approximation sample_size_proportion( p0 = 0.85, p1 = 0.90, alpha = 0.05, power = 0.8, alternative = "two.sided", test = "score", power_method = "normal" )
Calculates the minimum sample size whose two-sided confidence interval has
total width no greater than twice half_width, or whose one-sided limit is
no farther than half_width from the anticipated sample proportion.
sample_size_proportion_ci( p, half_width, conf.level = 0.95, interval = c("two.sided", "lower", "upper"), method = c("wilson", "wald", "wald-cc", "agresti-coull", "jeffreys", "wilson-cc", "clopper-pearson"), n.max = 1e+06 )sample_size_proportion_ci( p, half_width, conf.level = 0.95, interval = c("two.sided", "lower", "upper"), method = c("wilson", "wald", "wald-cc", "agresti-coull", "jeffreys", "wilson-cc", "clopper-pearson"), n.max = 1e+06 )
p |
Anticipated proportion in |
half_width |
For a two-sided interval, one half of the total interval width. For a one-sided interval, the maximum distance from the anticipated proportion to the confidence limit. |
conf.level |
Confidence level. Default 0.95. |
interval |
One of |
method |
Confidence interval method. One of |
n.max |
Maximum sample size considered. Default 1000000. |
An object of class sample_size_proportion_ci. The required
sample size is available as x$n. The returned object also contains
the achieved half-width and the exact binomial coverage at the assumed
value of p.
sample_size_proportion_ci(p = 0.3, half_width = 0.05) sample_size_proportion_ci( p = 0.3, half_width = 0.03, method = "clopper-pearson" )sample_size_proportion_ci(p = 0.3, half_width = 0.05) sample_size_proportion_ci( p = 0.3, half_width = 0.03, method = "clopper-pearson" )
Returns minimum CLSI EP17-A2 design requirements and, optionally, counts observed in a supplied data set. Differences are descriptive only; the function does not issue a pass/fail conclusion.
sensitivity_design( method = c("classical", "profile", "probit", "loq", "verification"), data = NULL, result = NULL, sample = NULL, lot = NULL, day = NULL, concentration = NULL, limit = c("lob", "lod", "loq") )sensitivity_design( method = c("classical", "profile", "probit", "loq", "verification"), data = NULL, result = NULL, sample = NULL, lot = NULL, day = NULL, concentration = NULL, limit = c("lob", "lod", "loq") )
method |
One or more of |
data |
Optional study data. |
result, sample, lot, day, concentration
|
Optional column names used to summarize actual study counts. |
limit |
Detection limit for a verification design. |
An object of class sensitivity_design.
CLSI. Evaluation of Detection Capability for Clinical Laboratory Measurement Procedures. EP17-A2, 2nd ed. 2012.
sensitivity_design(c("classical", "loq")) design_data <- data.frame( result = 1:8, sample = rep(c("S1", "S2"), each = 4), lot = rep(c("A", "B"), 4), day = rep(1:2, each = 4) ) sensitivity_design("verification", data = design_data, result = "result", sample = "sample", lot = "lot", day = "day", limit = "lod")sensitivity_design(c("classical", "loq")) design_data <- data.frame( result = 1:8, sample = rep(c("S1", "S2"), each = 4), lot = rep(c("A", "B"), 4), day = rep(1:2, each = 4) ) sensitivity_design("verification", data = design_data, result = "result", sample = "sample", lot = "lot", day = "day", limit = "lod")
Establishes a LoB from replicate-level blank results using the CLSI EP17-A2 nonparametric, parametric, or zero-LoB procedure. With two or three reagent lots, lots are analyzed separately and the maximum estimate is reported; four or more lots are combined by default.
sensitivity_lob( data, result, sample, lot = NULL, method = c("nonparametric", "parametric", "zero"), alpha = 0.05, lot_rule = c("ep17", "separate", "combined"), exclude = NULL )sensitivity_lob( data, result, sample, lot = NULL, method = c("nonparametric", "parametric", "zero"), alpha = 0.05, lot_rule = c("ep17", "separate", "combined"), exclude = NULL )
data |
A data frame containing replicate-level results. |
result, sample
|
Column names for the numeric result and blank sample ID. |
lot |
Optional reagent-lot column. |
method |
One of |
alpha |
Type I error risk. |
lot_rule |
EP17 lot handling, forced separate analysis, or forced pooling. |
exclude |
Optional row indices or logical exclusion indicator. Exclusions are recorded in the returned object. |
An object of class sensitivity_lob.
CLSI. Evaluation of Detection Capability for Clinical Laboratory Measurement Procedures. EP17-A2, 2nd ed. 2012.
blank <- data.frame( sample = rep(c("blank_1", "blank_2"), each = 5), result = c(0.02, 0.04, 0.03, 0.05, 0.01, 0.03, 0.06, 0.04, 0.02, 0.05) ) lob <- sensitivity_lob(blank, result = "result", sample = "sample") lob$estimateblank <- data.frame( sample = rep(c("blank_1", "blank_2"), each = 5), result = c(0.02, 0.04, 0.03, 0.05, 0.01, 0.03, 0.06, 0.04, 0.02, 0.05) ) lob <- sensitivity_lob(blank, result = "result", sample = "sample") lob$estimate
Establishes LoD using the classical, nonparametric trial, precision-profile, or probit approach described in CLSI EP17-A2.
sensitivity_lod( data, result = NULL, sample = NULL, lob, lot = NULL, concentration = NULL, detected = NULL, method = c("classical", "nonparametric", "profile", "probit"), beta = 0.05, profile_model = c("linear", "quadratic", "sadler", "vfp"), concentration_scale = c("log10", "identity"), total = NULL, strata = NULL, model_no = 1:9, lot_rule = c("ep17", "separate", "combined"), exclude = NULL )sensitivity_lod( data, result = NULL, sample = NULL, lob, lot = NULL, concentration = NULL, detected = NULL, method = c("classical", "nonparametric", "profile", "probit"), beta = 0.05, profile_model = c("linear", "quadratic", "sadler", "vfp"), concentration_scale = c("log10", "identity"), total = NULL, strata = NULL, model_no = 1:9, lot_rule = c("ep17", "separate", "combined"), exclude = NULL )
data |
A replicate-level data frame, or a completed |
result, sample
|
Column names for result and sample ID. |
lob |
Numeric LoB or a |
lot |
Optional reagent-lot column. |
concentration |
Concentration column for probit analysis. |
detected |
Optional detection indicator or hit-count column for probit. |
method |
LoD method. |
beta |
Type II error risk. |
profile_model |
Precision-profile model. |
concentration_scale |
Probit concentration scale. |
total |
Optional total-count column for summarized probit data. |
strata |
Optional additional probit stratification columns. |
model_no |
VFP model numbers when |
lot_rule |
EP17, separate, or combined lot handling. |
exclude |
Optional excluded rows. |
An object of class sensitivity_lod.
CLSI. Evaluation of Detection Capability for Clinical Laboratory Measurement Procedures. EP17-A2, 2nd ed. 2012.
low <- data.frame( sample = rep(c("low_1", "low_2"), each = 5), result = c(0.22, 0.26, 0.24, 0.25, 0.23, 0.31, 0.29, 0.33, 0.30, 0.32) ) lod <- sensitivity_lod(low, "result", "sample", lob = 0.10, method = "classical") lod$estimatelow <- data.frame( sample = rep(c("low_1", "low_2"), each = 5), result = c(0.22, 0.26, 0.24, 0.25, 0.23, 0.31, 0.29, 0.33, 0.30, 0.32) ) lod <- sensitivity_lod(low, "result", "sample", lob = 0.10, method = "classical") lod$estimate
Establishes LoQ from Westgard total error, RMS error, a precision goal, or a user-supplied accuracy function. The original candidate and the LoD- constrained reported LoQ are retained separately.
sensitivity_loq( data, result, sample, assigned, lot = NULL, method = c("westgard", "rms", "precision", "custom"), goal, goal_scale = c("relative", "absolute"), lod = NULL, k = 2, accuracy_function = NULL, profile = FALSE, profile_model = c("linear", "quadratic"), lot_rule = c("ep17", "separate", "combined"), exclude = NULL, ... )sensitivity_loq( data, result, sample, assigned, lot = NULL, method = c("westgard", "rms", "precision", "custom"), goal, goal_scale = c("relative", "absolute"), lod = NULL, k = 2, accuracy_function = NULL, profile = FALSE, profile_model = c("linear", "quadratic"), lot_rule = c("ep17", "separate", "combined"), exclude = NULL, ... )
data |
Replicate-level data frame. |
result, sample
|
Column names for result and sample ID. |
assigned |
Assigned-value column or numeric value/vector. |
lot |
Optional reagent-lot column. |
method |
Accuracy definition. |
goal |
Accuracy goal; proportions are used for relative goals. |
goal_scale |
Relative or absolute scale. |
lod |
Optional numeric LoD or |
k |
SD multiplier for the Westgard definition. |
accuracy_function |
Function used by |
profile |
Fit an error profile and calculate its goal crossing? |
profile_model |
Linear or quadratic error profile. |
lot_rule |
EP17, separate, or combined lot handling. |
exclude |
Optional excluded rows. |
... |
Additional arguments passed to |
An object of class sensitivity_loq.
CLSI. Evaluation of Detection Capability for Clinical Laboratory Measurement Procedures. EP17-A2, 2nd ed. 2012.
loq_data <- data.frame( sample = rep(paste0("L", 1:3), each = 4), assigned = rep(c(0.5, 1, 2), each = 4), result = c(0.42, 0.48, 0.51, 0.46, 0.91, 1.02, 0.96, 1.05, 1.91, 2.04, 1.98, 2.08) ) loq <- sensitivity_loq( loq_data, "result", "sample", assigned = "assigned", method = "precision", goal = 0.15, goal_scale = "relative" ) loq$summaryloq_data <- data.frame( sample = rep(paste0("L", 1:3), each = 4), assigned = rep(c(0.5, 1, 2), each = 4), result = c(0.42, 0.48, 0.51, 0.46, 0.91, 1.02, 0.96, 1.05, 1.91, 2.04, 1.98, 2.08) ) loq <- sensitivity_loq( loq_data, "result", "sample", assigned = "assigned", method = "precision", goal = 0.15, goal_scale = "relative" ) loq$summary
Calculates the proportion of verification results consistent with a stated claim, its one-sided Wilson score limits, and the CLSI EP17-A2 Table 1 boundary. No pass/fail field or regulatory conclusion is produced.
sensitivity_verify( data, result, sample, limit = c("lob", "lod", "loq"), claim, lob = NULL, assigned = NULL, allowable_error = NULL, error_scale = c("relative", "absolute"), alpha = 0.05, exclude = NULL )sensitivity_verify( data, result, sample, limit = c("lob", "lod", "loq"), claim, lob = NULL, assigned = NULL, allowable_error = NULL, error_scale = c("relative", "absolute"), alpha = 0.05, exclude = NULL )
data |
Replicate-level verification data. |
result, sample
|
Column names for result and sample ID. |
limit |
One of |
claim |
Stated limit being verified. |
lob |
LoB threshold required for LoD verification. |
assigned |
Assigned-value column or vector for LoQ verification. |
allowable_error |
Accuracy window half-width for LoQ verification. |
error_scale |
Relative or absolute LoQ error window. |
alpha |
One-sided confidence error probability. |
exclude |
Optional excluded rows. |
An object of class sensitivity_verification.
CLSI. Evaluation of Detection Capability for Clinical Laboratory Measurement Procedures. EP17-A2, 2nd ed. 2012.
verification <- data.frame( sample = rep(c("blank_1", "blank_2"), each = 10), result = c(rep(0.03, 9), 0.07, rep(0.04, 9), 0.08) ) verified <- sensitivity_verify( verification, "result", "sample", limit = "lob", claim = 0.05 ) verified$resultverification <- data.frame( sample = rep(c("blank_1", "blank_2"), each = 10), result = c(rep(0.03, 9), 0.07, rep(0.04, 9), 0.08) ) verified <- sensitivity_verify( verification, "result", "sample", limit = "lob", claim = 0.05 ) verified$result
Applies the mass-balance equation for mixing a sample and a spiking material. Arguments are vectorized using ordinary R recycling.
spike_concentration( sample_concentration, sample_volume, stock_concentration, spike_volume )spike_concentration( sample_concentration, sample_volume, stock_concentration, spike_volume )
sample_concentration |
Concentration in the sample before spiking. |
sample_volume |
Volume of sample used. |
stock_concentration |
Concentration of the spiking material. |
spike_volume |
Volume of spiking material added. |
A data frame containing total volume, spike fraction, concentration added by the spike, and final calculated concentration.
CLSI. Establishing and Verifying an Extended Measuring Interval Through Specimen Dilution and Spiking. EP34, 1st ed. 2018.
spike_concentration( sample_concentration = 10, sample_volume = 0.95, stock_concentration = 210, spike_volume = 0.05 )spike_concentration( sample_concentration = 10, sample_volume = 0.95, stock_concentration = 210, spike_volume = 0.05 )
Calculates the difference between analyte-spiked and equal-volume solvent-control means and expresses that difference as a percentage of the known added concentration. No acceptance criterion is applied.
spike_recovery( data, sample, result, condition, analyte_level, solvent_level, added_concentration = NULL, sample_volume = NULL, stock_concentration = NULL, spike_volume = NULL, conf.level = 0.95 )spike_recovery( data, sample, result, condition, analyte_level, solvent_level, added_concentration = NULL, sample_volume = NULL, stock_concentration = NULL, spike_volume = NULL, conf.level = 0.95 )
data |
Data frame in long format. |
sample |
Sample-identification column. |
result |
Numeric measurement-result column. |
condition |
Column distinguishing analyte-spiked and solvent-control preparations. |
analyte_level |
Value identifying the analyte-spiked preparation. |
solvent_level |
Value identifying the solvent-control preparation. |
added_concentration |
A finite scalar or numeric column containing the
theoretical concentration added to the final mixture. When omitted,
|
sample_volume, stock_concentration, spike_volume
|
Finite scalars or numeric columns used to calculate the added concentration. |
conf.level |
Confidence level for the across-sample mean recovery. |
An object of class spike_recovery.
CLSI. Establishing and Verifying an Extended Measuring Interval Through Specimen Dilution and Spiking. EP34, 1st ed. 2018.
spike_data <- data.frame( sample = rep(c("S1", "S2"), each = 4), condition = rep(rep(c("spiked", "control"), each = 2), 2), result = c(20.1, 19.9, 10.0, 10.2, 30.2, 29.8, 20.1, 19.9) ) recovery <- spike_recovery( spike_data, "sample", "result", "condition", analyte_level = "spiked", solvent_level = "control", added_concentration = 10 ) recovery$resultsspike_data <- data.frame( sample = rep(c("S1", "S2"), each = 4), condition = rep(rep(c("spiked", "control"), each = 2), 2), result = c(20.1, 19.9, 10.0, 10.2, 30.2, 29.8, 20.1, 19.9) ) recovery <- spike_recovery( spike_data, "sample", "result", "condition", analyte_level = "spiked", solvent_level = "control", added_concentration = 10 ) recovery$results
Split an input data frame into a named list of data frames before analysis.
Cutpoints are applied to one numeric variable using left-closed,
right-open intervals. For example, cutpoints c(100, 500) create
[-Inf, 100), [100, 500), and [500, Inf).
split_by_cutpoints( data, variable, cutpoints, labels = NULL, na_action = c("error", "drop"), drop_empty = FALSE )split_by_cutpoints( data, variable, cutpoints, labels = NULL, na_action = c("error", "drop"), drop_empty = FALSE )
data |
A data frame. |
variable |
A single character string naming the numeric variable used to split the rows. |
cutpoints |
A non-empty, finite, strictly increasing numeric vector. |
labels |
Optional unique names for the returned data frames. Its length
must be |
na_action |
How non-finite splitting values are handled: |
drop_empty |
Whether empty intervals are removed. The default is
|
A named list of data frames with class cutpoint_split. The
segment_info attribute records interval bounds, labels, and row counts.
parts <- split_by_cutpoints( ivd_mcr_example, variable = "ref", cutpoints = c(18, 26) ) parts parts$segment_1 fits <- lapply(parts, function(d) mcr(d, "sid", "test", "ref"))parts <- split_by_cutpoints( ivd_mcr_example, variable = "ref", cutpoints = c(18, 26) ) parts parts$segment_1 fits <- lapply(parts, function(d) mcr(d, "sid", "test", "ref"))
Split an input data frame into a named list of data frames before analysis. Factor levels retain their declared order; character and logical values use first-appearance order. The splitting column is retained in every returned data frame.
split_by_factors( data, variable, na_action = c("drop", "error"), drop_empty = TRUE )split_by_factors( data, variable, na_action = c("drop", "error"), drop_empty = TRUE )
data |
A data frame. |
variable |
A single character string naming the factor, character, or logical variable used to split the rows. |
na_action |
How missing splitting values are handled: |
drop_empty |
Whether unused factor levels are removed. The default is
|
A named list of data frames with class factor_split. List names
are the original factor levels or categorical values. The group_info
attribute records their order and row counts.
d <- data.frame( batch = factor(c("Batch-A", "Batch-A", "Batch-B")), result = c(10.1, 9.9, 10.4) ) parts <- split_by_factors(d, variable = "batch") parts parts[["Batch-A"]] means <- lapply(parts, function(z) mean(z$result))d <- data.frame( batch = factor(c("Batch-A", "Batch-A", "Batch-B")), result = c(10.1, 9.9, 10.4) ) parts <- split_by_factors(d, variable = "batch") parts parts[["Batch-A"]] means <- lapply(parts, function(z) mean(z$result))
Each storage condition is baseline-corrected to its own first time point. Absolute and relative biases are computed and compared across conditions at matched time points.
stability_bias( data, condition, time, value, reference_condition = NULL, limit = NULL, bias_type = c("relative", "absolute"), time_unit = "d" )stability_bias( data, condition, time, value, reference_condition = NULL, limit = NULL, bias_type = c("relative", "absolute"), time_unit = "d" )
data |
A data frame. |
condition |
Column name for storage condition (e.g. temperature). |
time |
Column name for time point. |
value |
Column name for measurement value. |
reference_condition |
Reference condition for between-condition comparison; NULL uses the first occurring condition. |
limit |
A positive number for symmetric allowable bias; NULL to skip. |
bias_type |
|
time_unit |
Time unit: m, min, h, d, month, or y. |
An S3 object of class "stability_bias".
set.seed(42) df <- data.frame(cond = rep(c("2-8C","25C"), each = 8), t = rep(c(0,1,3,7), 4), val = c(rnorm(4,100,2), rnorm(4,98,2), rnorm(4,100,2), rnorm(4,92,3))) stability_bias(df, "cond", "t", "val", limit = 5)set.seed(42) df <- data.frame(cond = rep(c("2-8C","25C"), each = 8), t = rep(c(0,1,3,7), 4), val = c(rnorm(4,100,2), rnorm(4,98,2), rnorm(4,100,2), rnorm(4,92,3))) stability_bias(df, "cond", "t", "val", limit = 5)
Based on the ratio of expected drift to allowable drift and the reproducibility variability, looks up the minimum number of time points required per regression series in the EP25 Appendix A tables.
stability_plan( allowable_drift, variability, replicates = 1L, expected_drift = NULL, power = c(0.8, 0.9), mode = c("simple", "components"), bias_type = c("relative", "absolute") )stability_plan( allowable_drift, variability, replicates = 1L, expected_drift = NULL, power = c(0.8, 0.9), mode = c("simple", "components"), bias_type = c("relative", "absolute") )
allowable_drift |
Allowable drift (positive number). |
variability |
Repeatability CV/SD (simple mode) or a data frame of variance components. |
replicates |
Number of replicate measurements per time point. |
expected_drift |
Expected drift; NULL defaults to half of allowable_drift. |
power |
Statistical power: 0.8 or 0.9. |
mode |
|
bias_type |
|
An S3 object of class "stability_plan".
stability_plan(4, 1.5, replicates = c(1,2,3)) comp <- data.frame(source = c("repeatability","lot","operator"), variability = c(1.5,1.0,0.8), levels = c(1,3,2)) stability_plan(4, comp, replicates = c(1,2,3), mode = "components")stability_plan(4, 1.5, replicates = c(1,2,3)) comp <- data.frame(source = c("repeatability","lot","operator"), variability = c(1.5,1.0,0.8), levels = c(1,3,2)) stability_plan(4, comp, replicates = c(1,2,3), mode = "components")
Performs simple linear regression on a single condition's measurements (self mode) or on paired biases between test and reference conditions (compare mode), with one-sided confidence limits to evaluate whether drift remains within allowable limits.
stability_regression( data, time, value, condition = NULL, mode = c("self", "compare"), test_condition = NULL, reference_condition = NULL, bias_type = c("relative", "absolute"), direction = c("auto", "decrease", "increase"), conf.level = 0.95, limit = NULL, time_unit = "d" )stability_regression( data, time, value, condition = NULL, mode = c("self", "compare"), test_condition = NULL, reference_condition = NULL, bias_type = c("relative", "absolute"), direction = c("auto", "decrease", "increase"), conf.level = 0.95, limit = NULL, time_unit = "d" )
data |
A data frame. |
time |
Column name for time point. |
value |
Column name for measurement value. |
condition |
Column name for storage condition; required for compare mode. |
mode |
|
test_condition |
Test condition; auto-selected if NULL. |
reference_condition |
Reference condition; NULL uses the first condition. |
bias_type |
|
direction |
|
conf.level |
One-sided confidence level, default 0.95. |
limit |
A positive number for symmetric allowable bias; NULL to skip. |
time_unit |
Time unit: m, min, h, d, month, or y. |
An S3 object of class "stability_regression".
set.seed(42) df <- data.frame(cond = rep(c("2-8C","25C"), each = 8), t = rep(c(0,1,3,7), 4), val = c(rnorm(4,100,2), rnorm(4,98,2), rnorm(4,100,2), rnorm(4,92,3))) stability_regression(df, "t", "val", "cond", test_condition = "25C", limit = 5) set.seed(42) df <- data.frame(cond = rep(c("Ref","Test"), each = 8), t = rep(c(0,1,3,7), 4), val = c(rnorm(4,100,2), rnorm(4,99,2), rnorm(4,100,2), rnorm(4,94,3))) stability_regression(df, "t", "val", "cond", mode = "compare", test_condition = "Test", reference_condition = "Ref", limit = 5)set.seed(42) df <- data.frame(cond = rep(c("2-8C","25C"), each = 8), t = rep(c(0,1,3,7), 4), val = c(rnorm(4,100,2), rnorm(4,98,2), rnorm(4,100,2), rnorm(4,92,3))) stability_regression(df, "t", "val", "cond", test_condition = "25C", limit = 5) set.seed(42) df <- data.frame(cond = rep(c("Ref","Test"), each = 8), t = rep(c(0,1,3,7), 4), val = c(rnorm(4,100,2), rnorm(4,99,2), rnorm(4,100,2), rnorm(4,94,3))) stability_regression(df, "t", "val", "cond", mode = "compare", test_condition = "Test", reference_condition = "Ref", limit = 5)
Given a fitted regression model, computes the time at which the point estimate or one-sided confidence limit first reaches the allowable bias. May extrapolate beyond the observed time range.
stability_time(object, limit = NULL, max_time = NULL)stability_time(object, limit = NULL, max_time = NULL)
object |
A |
limit |
Symmetric allowable bias. |
max_time |
Maximum search time; NULL defaults to 100x the maximum observed time. |
An S3 object of class "stability_time".
set.seed(42) df <- data.frame(cond = rep(c("2-8C","25C"), each = 8), t = rep(c(0,1,3,7), 4), val = c(rnorm(4,100,2), rnorm(4,98,2), rnorm(4,100,2), rnorm(4,92,3))) r <- stability_regression(df, "t", "val", "cond", test_condition = "25C", limit = 5) stability_time(r) set.seed(42) df <- data.frame(cond = rep(c("Ref","Test"), each = 8), t = rep(c(0,1,3,7), 4), val = c(rnorm(4,100,2), rnorm(4,99,2), rnorm(4,100,2), rnorm(4,94,3))) r2 <- stability_regression(df, "t", "val", "cond", mode = "compare", test_condition = "Test", reference_condition = "Ref", limit = 5) stability_time(r2, limit = 5)set.seed(42) df <- data.frame(cond = rep(c("2-8C","25C"), each = 8), t = rep(c(0,1,3,7), 4), val = c(rnorm(4,100,2), rnorm(4,98,2), rnorm(4,100,2), rnorm(4,92,3))) r <- stability_regression(df, "t", "val", "cond", test_condition = "25C", limit = 5) stability_time(r) set.seed(42) df <- data.frame(cond = rep(c("Ref","Test"), each = 8), t = rep(c(0,1,3,7), 4), val = c(rnorm(4,100,2), rnorm(4,99,2), rnorm(4,100,2), rnorm(4,94,3))) r2 <- stability_regression(df, "t", "val", "cond", mode = "compare", test_condition = "Test", reference_condition = "Ref", limit = 5) stability_time(r2, limit = 5)
Summarize a commutability assessment
## S3 method for class 'commutability_result' summary(object, ...)## S3 method for class 'commutability_result' summary(object, ...)
object |
A commutability_result object. |
... |
Reserved for the S3 generic. |
The unchanged object, invisibly.
Summarizes all key analysis information already executed in a fourfold_table object, formatted following summary.mcr() pattern (mcr.R).
## S3 method for class 'fourfold_table' summary(object, digits = 3, ...)## S3 method for class 'fourfold_table' summary(object, digits = 3, ...)
object |
a fourfold_table object |
digits |
Number of decimal places, default 3 |
... |
Reserved arguments |
Invisible fourfold_table object
tab <- counts_to_table(tp = 85, fp = 3, tn = 90, fn = 2, candidate = "new method", reference = "gold standard") summary(tab) tab <- diagnostics(tab); tab <- kappa(tab); tab <- mcnemar(tab) summary(tab)tab <- counts_to_table(tp = 85, fp = 3, tn = 90, fn = 2, candidate = "new method", reference = "gold standard") summary(tab) tab <- diagnostics(tab); tab <- kappa(tab); tab <- mcnemar(tab) summary(tab)
Summarize key information from all executed analyses in the mcr object
(descriptive statistics, correlation analysis, regression analysis,
outlier detection, Bland-Altman analysis, and bias analysis).
## S3 method for class 'mcr' summary(object, ...)## S3 method for class 'mcr' summary(object, ...)
object |
|
... |
Additional arguments |
Invisible mcr object
df <- data.frame(sid = 1:30, test = rnorm(30, 50, 10), ref = rnorm(30, 50, 10)) obj <- mcr(df, "sid", "test", "ref") summary(obj) obj <- correlation(obj) obj <- regression(obj, method = "ols") obj <- bland_altman(obj) summary(obj)df <- data.frame(sid = 1:30, test = rnorm(30, 50, 10), ref = rnorm(30, 50, 10)) obj <- mcr(df, "sid", "test", "ref") summary(obj) obj <- correlation(obj) obj <- regression(obj, method = "ols") obj <- bland_altman(obj) summary(obj)
Summarize all executed analyses in a precision object, including data description,
analysis status checklist, outlier detection, normality tests, variance components,
confidence intervals, and precision profile.
## S3 method for class 'precision' summary(object, ...)## S3 method for class 'precision' summary(object, ...)
object |
|
... |
Reserved arguments |
Invisible precision object
data(VCAdata1, package = "VCA") obj <- precision(VCAdata1, y ~ day/run, by = "sample") summary(obj)data(VCAdata1, package = "VCA") obj <- precision(VCAdata1, y ~ day/run, by = "sample") summary(obj)
Output key information from all analyses performed on the roc object.
## S3 method for class 'roc' summary(object, ...)## S3 method for class 'roc' summary(object, ...)
object |
roc object |
... |
reserved arguments |
invisible roc object
obj <- roc(ivd_roc_example, cols = c("x1", "x2"), reference = "ref") summary(obj) obj <- auc(obj) obj <- cutoff(obj) obj <- mlr(obj) summary(obj)obj <- roc(ivd_roc_example, cols = c("x1", "x2"), reference = "ref") summary(obj) obj <- auc(obj) obj <- cutoff(obj) obj <- mlr(obj) summary(obj)
Perform Tukey HSD pairwise comparisons on an ANOVA result, with compact letter display.
## S3 method for class 'bottle_anova' tukey(x, term = NULL, conf.level = NULL, ...)## S3 method for class 'bottle_anova' tukey(x, term = NULL, conf.level = NULL, ...)
x |
A |
term |
Effect term to analyse (character vector); |
conf.level |
Confidence level; |
... |
Other arguments (unused) |
An S3 object of class "tukey" with components:
response_name |
Response variable name |
conf.level |
Confidence level |
tukey_list |
List, one element per term, each with matrix, means, cld |
Note: The original bottle_anova object's $tukey_results is also updated.
obj <- bottle_anova(ivd_bottle_example, value ~ bottle) res <- tukey(obj) resobj <- bottle_anova(ivd_bottle_example, value ~ bottle) res <- tukey(obj) res
Calculates the unweighted mean of laboratory means and its standard error.
Common calibration or group-correlated components should be supplied
separately to uncertainty_combine() so they are not counted repeatedly.
uncertainty_characterization( data, laboratory, result, name = "characterization", relative = FALSE )uncertainty_characterization( data, laboratory, result, name = "characterization", relative = FALSE )
data |
Data frame. |
laboratory |
Laboratory or measurement-procedure column. |
result |
Numeric result column. |
name |
Component name. |
relative |
Return the component relative to the assigned value. |
An uncertainty_characterization object.
CLSI EP30-A; CLSI EP32-R.
characterization_data <- data.frame( laboratory = rep(paste0("Lab", 1:4), each = 3), result = c(99, 100, 101, 100, 101, 100, 98, 99, 100, 101, 102, 101) ) characterization <- uncertainty_characterization( characterization_data, "laboratory", "result" ) characterization$laboratory_summarycharacterization_data <- data.frame( laboratory = rep(paste0("Lab", 1:4), each = 3), result = c(99, 100, 101, 100, 101, 100, 98, 99, 100, 101, 102, 101) ) characterization <- uncertainty_characterization( characterization_data, "laboratory", "result" ) characterization$laboratory_summary
Applies the GUM first-order covariance propagation formula c' Sigma c.
Components from any estimator in this module can be supplied directly.
uncertainty_combine( ..., sensitivity = NULL, correlation = NULL, value = NULL, coverage = 0.95, k = NULL )uncertainty_combine( ..., sensitivity = NULL, correlation = NULL, value = NULL, coverage = 0.95, k = NULL )
... |
Uncertainty components, analysis objects containing |
sensitivity |
Optional sensitivity coefficient per component. |
correlation |
Optional correlation matrix. |
value |
Optional output quantity value, needed to mix relative and absolute components. |
coverage |
Coverage probability. |
k |
Optional fixed coverage factor. Otherwise a normal or effective-df Student t factor is used. |
An uncertainty_budget object.
CLSI EP29-A.
repeatability <- uncertainty_type_a( c(9.9, 10.0, 10.1, 10.0), "repeatability", quantity = "mean" ) calibrator <- uncertainty_type_b( "calibrator", estimate = 10, uncertainty = 0.2, k = 2, distribution = "normal" ) budget <- uncertainty_combine(repeatability, calibrator, value = 10) budget$componentsrepeatability <- uncertainty_type_a( c(9.9, 10.0, 10.1, 10.0), "repeatability", quantity = "mean" ) calibrator <- uncertainty_type_b( "calibrator", estimate = 10, uncertainty = 0.2, k = 2, distribution = "normal" ) budget <- uncertainty_combine(repeatability, calibrator, value = 10) budget$components
Uses the EP30 one-way ANOVA calculations, including the effective replicate count for an unbalanced design and the inhomogeneity that can be hidden by measurement repeatability. The reported component is the larger of the observed between-unit SD and the hidden-inhomogeneity estimate.
uncertainty_homogeneity( data, unit, result, name = "between-unit homogeneity", relative = FALSE )uncertainty_homogeneity( data, unit, result, name = "between-unit homogeneity", relative = FALSE )
data |
Data frame in long format. |
unit |
Bottle, vial, or material-unit column. |
result |
Numeric measurement-result column. |
name |
Component name. |
relative |
Return the component on a relative scale. |
An uncertainty_homogeneity object.
CLSI EP30-A.
homogeneity_data <- data.frame( unit = rep(paste0("V", 1:4), each = 2), result = c(99, 100, 101, 100, 98, 99, 102, 101) ) homogeneity <- uncertainty_homogeneity( homogeneity_data, "unit", "result" ) homogeneity$componenthomogeneity_data <- data.frame( unit = rep(paste0("V", 1:4), each = 2), result = c(99, 100, 101, 100, 98, 99, 102, 101) ) homogeneity <- uncertainty_homogeneity( homogeneity_data, "unit", "result" ) homogeneity$component
Uses a one-way random-effects ANOVA when runs contain replicates. The object reports within-run, between-run, single-result, and overall-mean estimates.
uncertainty_iqc( data, result, run = NULL, quantity = c("single", "mean"), name = "IQC", relative = FALSE )uncertainty_iqc( data, result, run = NULL, quantity = c("single", "mean"), name = "IQC", relative = FALSE )
data |
Data frame. |
result |
Numeric result column. |
run |
Optional run column. If omitted, the SD of all results is used. |
quantity |
Component returned in |
name |
Component name. |
relative |
Return the selected component on a relative scale. |
An uncertainty_iqc object.
CLSI EP29-A.
iqc_data <- data.frame( run = rep(1:5, each = 2), result = c(99, 101, 100, 102, 98, 100, 101, 103, 99, 100) ) iqc <- uncertainty_iqc(iqc_data, "result", run = "run") iqc$variance_componentsiqc_data <- data.frame( run = rep(1:5, each = 2), result = c(99, 101, 100, 102, 98, 100, 101, 103, 99, 100) ) iqc <- uncertainty_iqc(iqc_data, "result", run = "run") iqc$variance_components
The delta method numerically estimates sensitivity coefficients and applies GUM first-order propagation. Monte Carlo propagation samples the stored component distributions and returns a central quantile interval.
uncertainty_propagate( model, components, method = c("delta", "monte_carlo"), correlation = NULL, simulations = 100000L, coverage = 0.95, seed = NULL )uncertainty_propagate( model, components, method = c("delta", "monte_carlo"), correlation = NULL, simulations = 100000L, coverage = 0.95, seed = NULL )
model |
Function whose named arguments match component names. |
components |
Components or analysis objects containing components. |
method |
|
correlation |
Optional correlation matrix. Nonidentity correlation in Monte Carlo mode currently requires normal or standardized components. |
simulations |
Number of Monte Carlo draws. |
coverage |
Coverage probability. |
seed |
Optional random seed. |
An uncertainty_propagation object.
CLSI EP29-A.
numerator <- uncertainty_type_b( "numerator", estimate = 20, uncertainty = 0.4, distribution = "standard" ) denominator <- uncertainty_type_b( "denominator", estimate = 10, uncertainty = 0.1, distribution = "standard" ) propagated <- uncertainty_propagate( function(numerator, denominator) numerator / denominator, list(numerator, denominator), method = "delta" ) propagated$estimatenumerator <- uncertainty_type_b( "numerator", estimate = 20, uncertainty = 0.4, distribution = "standard" ) denominator <- uncertainty_type_b( "denominator", estimate = 10, uncertainty = 0.1, distribution = "standard" ) propagated <- uncertainty_propagate( function(numerator, denominator) numerator / denominator, list(numerator, denominator), method = "delta" ) propagated$estimate
Fits result on time and calculates the standard uncertainty at the requested shelf life as the slope standard error multiplied by shelf life. Separate components are returned for each optional storage condition.
uncertainty_stability( data, time, result, shelf_life, condition = NULL, name = "long-term stability", relative = FALSE )uncertainty_stability( data, time, result, shelf_life, condition = NULL, name = "long-term stability", relative = FALSE )
data |
Data frame. |
time |
Numeric storage-time column. |
result |
Numeric result column. |
shelf_life |
Positive time on the same scale as |
condition |
Optional storage-condition column. |
name |
Base component name. |
relative |
Return components relative to their fitted intercept-level mean. |
An uncertainty_stability object.
CLSI EP30-A.
stability_data <- data.frame( time = rep(0:4, each = 2), result = c(100.1, 99.9, 100.0, 99.8, 99.7, 99.9, 99.6, 99.8, 99.5, 99.7) ) stability_u <- uncertainty_stability( stability_data, "time", "result", shelf_life = 6 ) stability_u$summarystability_data <- data.frame( time = rep(0:4, each = 2), result = c(100.1, 99.9, 100.0, 99.8, 99.7, 99.9, 99.6, 99.8, 99.5, 99.7) ) stability_u <- uncertainty_stability( stability_data, "time", "result", shelf_life = 6 ) stability_u$summary
Accumulate uncertainty along a metrological traceability chain
uncertainty_traceability(stages, value = NULL, coverage = 0.95, k = NULL)uncertainty_traceability(stages, value = NULL, coverage = 0.95, k = NULL)
stages |
Named list. Each element contains the new uncertainty components introduced at that traceability stage. |
value |
Optional assigned value for absolute/relative conversion. |
coverage |
Coverage probability. |
k |
Optional fixed coverage factor. |
An uncertainty_traceability object.
CLSI EP29-A; CLSI EP32-R.
calibration <- uncertainty_type_b( "calibration", estimate = 100, uncertainty = 1, k = 2, distribution = "normal" ) transport <- uncertainty_type_b( "transport", estimate = 100, lower = 99.5, upper = 100.5, distribution = "rectangular" ) chain <- uncertainty_traceability( list(calibration = list(calibration), transport = list(transport)), value = 100 ) chain$summarycalibration <- uncertainty_type_b( "calibration", estimate = 100, uncertainty = 1, k = 2, distribution = "normal" ) transport <- uncertainty_type_b( "transport", estimate = 100, lower = 99.5, upper = 100.5, distribution = "rectangular" ) chain <- uncertainty_traceability( list(calibration = list(calibration), transport = list(transport)), value = 100 ) chain$summary
Uses the sample standard deviation for a future single result and the standard error for a mean. No normality or fitness-for-purpose decision is made.
uncertainty_type_a(x, name, quantity = c("single", "mean"), relative = FALSE)uncertainty_type_a(x, name, quantity = c("single", "mean"), relative = FALSE)
x |
Numeric repeated measurements. |
name |
Component name. |
quantity |
|
relative |
Store the standard uncertainty relative to the absolute mean. |
An uncertainty_component object.
CLSI EP29-A.
type_a <- uncertainty_type_a( c(10.1, 9.9, 10.0, 10.2, 9.8), name = "repeatability", quantity = "mean" ) type_atype_a <- uncertainty_type_a( c(10.1, 9.9, 10.0, 10.2, 9.8), name = "repeatability", quantity = "mean" ) type_a
Converts limits, an expanded uncertainty, or an already standardized value
to standard uncertainty. For bounded distributions lower and upper
define the interval. For normal and Student t distributions they define a
central interval with probability coverage.
uncertainty_type_b( name, estimate, lower = NULL, upper = NULL, uncertainty = NULL, distribution = c("rectangular", "triangular", "normal", "student_t", "u_shaped", "standard"), coverage = 0.95, k = NULL, df = Inf, relative = FALSE )uncertainty_type_b( name, estimate, lower = NULL, upper = NULL, uncertainty = NULL, distribution = c("rectangular", "triangular", "normal", "student_t", "u_shaped", "standard"), coverage = 0.95, k = NULL, df = Inf, relative = FALSE )
name |
Component name. |
estimate |
Best estimate of the input quantity. |
lower, upper
|
Optional interval limits. |
uncertainty |
Optional standard or expanded uncertainty. |
distribution |
Distribution model. |
coverage |
Central probability associated with normal or t limits. |
k |
Coverage factor when |
df |
Degrees of freedom for Student t or the component. |
relative |
Store uncertainty relative to the absolute estimate. |
An uncertainty_component object.
CLSI EP29-A.
rectangular <- uncertainty_type_b( name = "calibrator", estimate = 100, lower = 98, upper = 102, distribution = "rectangular" ) rectangular uncertainty_type_b( "certificate", estimate = 100, uncertainty = 2, k = 2, distribution = "normal" )rectangular <- uncertainty_type_b( name = "calibrator", estimate = 100, lower = 98, upper = 102, distribution = "rectangular" ) rectangular uncertainty_type_b( "certificate", estimate = 100, uncertainty = 2, k = 2, distribution = "normal" )
For each sample, run VCA (VCA::anovaVCA for balanced designs / ANOVA,
or VCA::remlVCA for REML) to estimate variance components, compute SD,
CV%, and their percentage of total variance. Results are stored in the
$results and $vc slots.
## S3 method for class 'precision' variance(x, digits = 4, method = c("auto", "anova", "reml"), ...)## S3 method for class 'precision' variance(x, digits = 4, method = c("auto", "anova", "reml"), ...)
x |
|
digits |
Number of decimal places, default |
method |
Estimation method: |
... |
Additional arguments passed to |
Updated precision object, $results contains per-sample VCA results,
$vc is the summary variance component table
data(VCAdata1, package = "VCA") obj <- precision(VCAdata1, y ~ day/run, by = "sample") obj <- variance(obj)data(VCAdata1, package = "VCA") obj <- precision(VCAdata1, y ~ day/run, by = "sample") obj <- variance(obj)
Backward-compatible alias for variance.precision
## S3 method for class 'precision' vc(x, digits = 4, method = c("auto", "anova", "reml"), ...)## S3 method for class 'precision' vc(x, digits = 4, method = c("auto", "anova", "reml"), ...)
x |
A |
digits |
Number of decimal places, default |
method |
Estimation method: |
... |
Additional arguments passed to the underlying VCA method. |
The same result as variance.precision: an updated
precision object, invisibly.
data(VCAdata1, package = "VCA") obj <- precision(VCAdata1, y ~ day/run, by = "sample") obj <- vc(obj)data(VCAdata1, package = "VCA") obj <- precision(VCAdata1, y ~ day/run, by = "sample") obj <- vc(obj)
Draws a Youden plot comparing two measurement systems. If target means and SDs are not provided, they are estimated from the data.
youden_plot( data, sample1, sample2, mean1 = NULL, mean2 = NULL, sd1 = NULL, sd2 = NULL )youden_plot( data, sample1, sample2, mean1 = NULL, mean2 = NULL, sd1 = NULL, sd2 = NULL )
data |
A data frame. |
sample1 |
Column name for sample 1. |
sample2 |
Column name for sample 2. |
mean1 |
Target mean for sample 1; NULL to estimate. |
mean2 |
Target mean for sample 2; NULL to estimate. |
sd1 |
Target SD for sample 1; NULL to estimate. |
sd2 |
Target SD for sample 2; NULL to estimate. |
An object of class "youden_plot" with summary statistics
and plot data. Use print() to show summary and plot()
to draw the Youden plot.
set.seed(42) df <- data.frame( m1 = rnorm(30, 100, 5), m2 = rnorm(30, 98, 5) ) res <- youden_plot(df, "m1", "m2", mean1 = 100, mean2 = 100, sd1 = 5, sd2 = 5) print(res) plot(res)set.seed(42) df <- data.frame( m1 = rnorm(30, 100, 5), m2 = rnorm(30, 98, 5) ) res <- youden_plot(df, "m1", "m2", mean1 = 100, mean2 = 100, sd1 = 5, sd2 = 5) print(res) plot(res)