Code
normal_test(dat, col = "candidate")
reference_interval(dat, col = "candidate")ivdtools is an R statistical toolkit for in vitro diagnostic (IVD) reagent evaluation, providing a set of reproducible workflows spanning data inspection, statistical analysis, and result summarization and visualization. The current version is 0.1.1, requires R >= 4.1.0, and is released under the MIT license.
The package covers method comparison, ROC, qualitative agreement, precision, reference intervals, stability, quality control, curve fitting, analytical sensitivity, outlier and normality assessment, and sample-size calculation. Statistical results should be interpreted in the context of a pre-specified study protocol, applicable standards, laboratory requirements, and clinical or analytical allowable limits, and cannot substitute for professional judgment.
Standalone interfaces complete one task at a time, for example:
normal_test(dat, col = "candidate")
reference_interval(dat, col = "candidate")Modules such as method comparison, ROC, qualitative analysis, and precision organize the analysis process using S3 objects:
summary() summarizes the analyses that have been completed;plot() produces plots from results already present in the object;predict() performs prediction in supported modules.data -> constructor -> analysis method -> updated object -> summary/plot/predict
The progressive interface requires reassignment:
obj <- analysis_method(obj)If you call only analysis_method(obj) without the obj <-, the new results will not accumulate into the original object.
| Module | Main entry | Key features |
|---|---|---|
| Method comparison | mcr() |
Descriptive statistics, correlation, OLS/WLS, Deming, weighted Deming, Passing–Bablok, Bland–Altman, bias and outlier analysis |
| ROC | roc() |
ROC curve, AUC, optimal cutoff, multivariate logistic regression and prediction |
| Qualitative analysis | raw_to_table(), counts_to_table() |
Four-fold table, diagnostic accuracy metrics, Kappa agreement and McNemar test |
| Precision | precision() |
Variance components, confidence intervals, outliers, normality and Sadler precision profile |
| Reference interval | reference_interval() |
Percentile, parametric and robust reference intervals |
| Bottle/lot ANOVA | bottle_anova() |
One-way or nested ANOVA, Tukey HSD and compact letter display |
| Stability | stability_bias(), stability_regression() |
Bias, stability regression, time to exceed limit, stability plan, MKT and Arrhenius models |
| Quality control | qc_chart(), youden_plot() |
Levey–Jennings chart, Westgard rules and Youden plot |
| Curve fitting | fit_equation() |
Linear, exponential, 4PLC, 5PLC and other equation fits, weighted/constrained fits and model comparison |
| Analytical sensitivity | lob_lod_loq() |
Limit of blank, limit of detection, limit of quantitation determination |
| Outliers and distribution | outliers_test(), normal_test() |
Grubbs, ESD, Dixon, IQR and multiple normality tests |
| Sample size | sample_size_*() |
Bland–Altman agreement, single-proportion confidence interval and one-arm target-value test |
The following code uses the deterministic example data bundled with the package. See 《Installing and Using the Analysis Environment》 for installation and loading instructions.
library(ivdtools)
mc <- mcr(
ivd_mcr_example,
id = "sid",
candidate = "test",
reference = "ref"
)
mc <- describe(mc)
mc <- correlation(mc, method = "pearson")
mc <- regression(mc, method = "deming")
mc <- bland_altman(mc, type = "difference")
summary(mc)
plot(mc, type = "regression")
plot(mc, type = "bland_altman")Regression methods include OLS, WLS, Deming, weighted Deming, and Passing-Bablok. The specific method, weights, confidence level, and outlier-handling strategy should be decided before analysis.
ro <- roc(
ivd_roc_example,
cols = c("x1", "x2"),
reference = "ref",
positive = 1
)
ro <- describe(ro)
ro <- auc(ro)
ro <- cutoff(ro)
ro <- mlr(ro, cols = c("x1", "x2"), name = "combined")
summary(ro)
plot(ro, mlr = "all", cutpoint = "Youden")The reference variable must be binary. If the original reference result is continuous, first use continuous_to_binary(), and explicitly record the threshold and the positive direction.
qa <- raw_to_table(
ivd_qualitative_example,
candidate = "new",
reference = "gold",
id = "id",
positive = "positive"
)
qa <- describe(qa)
qa <- diagnostics(qa)
qa <- kappa(qa)
qa <- mcnemar(qa)
summary(qa)When TP, FP, TN, FN counts are already available, you can also create an object with counts_to_table().
set.seed(20260806)
ri_data <- data.frame(value = rnorm(160, mean = 100, sd = 15))
ri <- reference_interval(
ri_data,
col = "value",
method = "all"
)
print(ri)
plot(ri)The percentile, parametric, or robust method should be chosen based on sample source, sample size, distribution characteristics, and the study protocol.
ba <- bottle_anova(ivd_bottle_example, value ~ bottle)
print(ba)
posthoc <- tukey(ba)
print(posthoc)# Outliers and normality
outliers_test(ri_data, "value", method = "grubbs")
normal_test(ri_data, "value", method = "shapiro")
# View available fit equations and Westgard rules
list_equation()
list_westgard()
# Sample size / power
sample_size_bland_altman(
power = 0.80,
mu = 0.2,
sd = 1,
delta = 2.5
)View the function documentation:
help(mcr,"ivdtools")View the help documentation and browse topic-specific files.
vignette("ivdtools")Visit the project homepage to view/download the complete function manual and help documentation.
The ivdtools R package provides statistical functions, while the ivdtools-analysis Skill provides a constrained automated analysis workflow for AI. Once the user supplies the data file, study design, and analysis requirements, the Skill uses ivdtools as its statistical engine to organize data pre-check, parameter confirmation, statistical analysis, result verification, and Chinese report generation.
The value of using the Skill in a conversation is not to “replace statistical judgment” but to standardize repetitive technical steps, and to save the data source, analysis parameters, excluded records, warnings, result tables, figures, and software environment together, reducing the risk of omissions and manual copy errors.
ivdtools-analysis is not installed with ivdtools; it can be obtained from the project homepage.
ivdtools mainly depends on ggplot2, ggrepel, VCA, VFP, minpack.lm, nloptr, nls2, nortest, and rlang.