diff --git a/DESCRIPTION b/DESCRIPTION index 4dd4377..6c9f602 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -10,15 +10,14 @@ Description: A complement to 'mcr' package, adding methods and functions to analyze the quantitative or qualitative performance for diagnostic assays. And outliers detection, reader precision and reference range are discussed. Most of the methods and algorithms refer to CLSI recommendations and NMPA - guidelines. In additional, relevant plots are constructed by ggplot2 statements. + guidelines. In additional, relevant plots are constructed by ggplot2. License: GPL (>= 3) URL: https://github.com/kaigu1990/mcradds, https://kaigu1990.github.io/mcradds/ BugReports: https://github.com/kaigu1990/mcradds/issues Encoding: UTF-8 LazyData: true Depends: - R (>= 3.6), - mcr (>= 1.3.2) + R (>= 3.6) Imports: boot, checkmate, @@ -34,6 +33,7 @@ Imports: Suggests: dplyr, knitr, + mcr, rmarkdown, spelling, testthat (>= 3.0.0), diff --git a/NAMESPACE b/NAMESPACE index b64965a..4497d0c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -19,6 +19,7 @@ export(h_fmt_num) export(h_fmt_range) export(h_summarize) export(mcreg) +export(mcreg2) export(nonparRI) export(pearsonTest) export(printSummary) @@ -35,7 +36,6 @@ exportMethods(getAccuracy) exportMethods(getOutlier) import(checkmate) import(ggplot2) -import(mcr) import(methods) importFrom(DescTools,BinomCI) importFrom(VCA,VCAinference) diff --git a/R/autoplot.R b/R/autoplot.R index a1acb73..52dc2bd 100644 --- a/R/autoplot.R +++ b/R/autoplot.R @@ -303,15 +303,14 @@ setMethod( #' @param legend.digits (`integer`)\cr the number of digits after the decimal point #' in the legend. #' -#' @seealso [mcr::mcreg()] to see the regression parameters. +#' @seealso [MCR-class] or [mcr::mcreg()] to see the regression parameters. #' #' @export #' #' @examples -#' #' # Using the default arguments for regression plot -#' data(creatinine, package = "mcr") -#' fit <- mcreg( +#' data("platelet") +#' fit <- mcreg2( #' x = platelet$Comparative, y = platelet$Candidate, #' method.reg = "Deming", method.ci = "jackknife" #' ) @@ -326,7 +325,7 @@ setMethod( #' ) setMethod( f = "autoplot", - signature = c("MCResult"), + signature = c("MCR"), definition = function(object, color = "black", fill = "lightgray", @@ -345,7 +344,7 @@ setMethod( x.title = NULL, y.title = NULL, main.title = NULL) { - assert_class(object, "MCResult") + assert_class(object, "MCR") assert_character(color) assert_character(fill) assert_number(size) @@ -365,8 +364,8 @@ setMethod( xrange <- range(df[["x"]]) yrange <- range(df[["y"]]) - slope <- formatC(object@glob.coef[2], format = "f", legend.digits) - intercept <- formatC(object@glob.coef[1], format = "f", legend.digits) + slope <- formatC(object@coef[2], format = "f", legend.digits) + intercept <- formatC(object@coef[1], format = "f", legend.digits) fm_text <- paste0("Y = ", slope, " * X + ", intercept) p <- ggplot(data = df, aes(x = .data$x, y = .data$y)) @@ -410,15 +409,15 @@ setMethod( ) shapes <- stats::setNames( c( - ifelse(is.null(reg.params[["linetype"]]), 1 , reg.params[["linetype"]]), - ifelse(is.null(identity.params[["linetype"]]), 1 , identity.params[["linetype"]]) + ifelse(is.null(reg.params[["linetype"]]), 1, reg.params[["linetype"]]), + ifelse(is.null(identity.params[["linetype"]]), 1, identity.params[["linetype"]]) ), c(fm_text, "Identity") ) cols <- stats::setNames( c( ifelse(is.null(reg.params[["col"]]), 1, reg.params[["col"]]), - ifelse(is.null(identity.params[["col"]]), 1 , identity.params[["col"]]) + ifelse(is.null(identity.params[["col"]]), 1, identity.params[["col"]]) ), c(fm_text, "Identity") ) diff --git a/R/mcr.R b/R/mcr.R index dab3f0c..9614c63 100644 --- a/R/mcr.R +++ b/R/mcr.R @@ -69,6 +69,26 @@ mcreg <- function(...) { mcr::mcreg(...) } +#' @rdname mcreg +#' @aliases mcreg +#' +#' @export +#' @examples +#' +#' # use `MCR` class instead of `MCResult` class in `mcr` package +#' mcreg2( +#' x = platelet$Comparative, y = platelet$Candidate, +#' method.reg = "Deming", method.ci = "jackknife" +#' ) +mcreg2 <- function(...) { + fit <- mcr::mcreg(...) + MCR( + data = fit@data, + coef = fit@glob.coef, + mnames = fit@mnames, + regmeth = fit@regmeth + ) +} # calcBias ---- diff --git a/R/package.R b/R/package.R index 3f999cc..1cfa590 100644 --- a/R/package.R +++ b/R/package.R @@ -4,7 +4,6 @@ #' "_PACKAGE" -#' @import mcr #' @import checkmate #' @import ggplot2 #' @import methods diff --git a/R/pkg_class.R b/R/pkg_class.R index 8963949..aff8feb 100644 --- a/R/pkg_class.R +++ b/R/pkg_class.R @@ -272,3 +272,48 @@ tpROC <- function(testROC, refROC, method, H0, stat) { testROC = testROC, refROC = refROC, method = method, H0 = H0, stat = stat ) } + +# MCR-class ---- + +#' Method Comparison Regression Class +#' +#' @description `r lifecycle::badge("experimental")` +#' +#' The `MCR` class serves as a simplified version of `MCResult` from `mcr` package. +#' As the `mcr` package are not available in CRAN, this class is took as the temporary +#' replacement of it, which only contains the some necessaries for `autoplot`. +#' +#' @slot data data +#' @slot coef coef +#' @slot mnames mnames +#' @slot regmeth regmeth +#' +#' @rdname MCR-class +#' @aliases MCR +setClass( + "MCR", + slots = c( + data = "data.frame", + coef = "numeric", + mnames = "character", + regmeth = "character" + ) +) + +# MCR-constructors ---- + +#' @rdname MCR-class +#' +#' @param data (`data.frame`)\cr original data. +#' @param coef (`numeric`)\cr a numeric vector contains slope and intercept. +#' @param mnames (`character`)\cr name of X and Y assays, default are 'Method1' +#' and 'Method2' if you have not defined them in `mcreg` function. +#' @param regmeth (`character`)\cr name of regression. +#' +#' @return An object of class `MCR`. +#' +MCR <- function(data, coef, mnames, regmeth) { + new("MCR", + data = data, coef = coef, mnames = mnames, regmeth = regmeth + ) +} diff --git a/_pkgdown.yml b/_pkgdown.yml index d2d5183..5e947a7 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -15,6 +15,7 @@ reference: - BAsummary - RefInt - tpROC + - MCR - title: Internal Helper Functions contents: - cat_with_newline diff --git a/cran-comments.md b/cran-comments.md index 9a3cec5..9080345 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -3,6 +3,8 @@ 0 errors | 0 warnings | 1 note * This is a new release. +* Suggests or Enhances not in mainstream repositories: `mcr`. Because `mcr` package +is not available in CRAN. But users can install it from archived version. ## revdepcheck results diff --git a/inst/WORDLIST b/inst/WORDLIST index 4cbe43c..c80128a 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -65,6 +65,7 @@ ananlysis apa ci clopper +coef confInt creatinin dL @@ -81,6 +82,7 @@ lipoprotein loa magrittr mcr +mnames nlr npa npv @@ -97,6 +99,7 @@ quasilinear quations refInt refROC +regmeth regmethod repo reproducibility diff --git a/man/MCR-class.Rd b/man/MCR-class.Rd new file mode 100644 index 0000000..44002a5 --- /dev/null +++ b/man/MCR-class.Rd @@ -0,0 +1,42 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/pkg_class.R +\docType{class} +\name{MCR-class} +\alias{MCR-class} +\alias{MCR} +\title{Method Comparison Regression Class} +\usage{ +MCR(data, coef, mnames, regmeth) +} +\arguments{ +\item{data}{(\code{data.frame})\cr original data.} + +\item{coef}{(\code{numeric})\cr a numeric vector contains slope and intercept.} + +\item{mnames}{(\code{character})\cr name of X and Y assays, default are 'Method1' +and 'Method2' if you have not defined them in \code{mcreg} function.} + +\item{regmeth}{(\code{character})\cr name of regression.} +} +\value{ +An object of class \code{MCR}. +} +\description{ +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} + +The \code{MCR} class serves as a simplified version of \code{MCResult} from \code{mcr} package. +As the \code{mcr} package are not available in CRAN, this class is took as the temporary +replacement of it, which only contains the some necessaries for \code{autoplot}. +} +\section{Slots}{ + +\describe{ +\item{\code{data}}{data} + +\item{\code{coef}}{coef} + +\item{\code{mnames}}{mnames} + +\item{\code{regmeth}}{regmeth} +}} + diff --git a/man/autoplot.Rd b/man/autoplot.Rd index 1c9e8c6..60441ea 100644 --- a/man/autoplot.Rd +++ b/man/autoplot.Rd @@ -3,7 +3,7 @@ \name{autoplot} \alias{autoplot} \alias{autoplot,BAsummary-method} -\alias{autoplot,MCResult-method} +\alias{autoplot,MCR-method} \title{Generate a \code{ggplot} for Bland-Altman Plot and Regression Plot} \usage{ autoplot(object, ...) @@ -32,7 +32,7 @@ autoplot(object, ...) main.title = NULL ) -\S4method{autoplot}{MCResult}( +\S4method{autoplot}{MCR}( object, color = "black", fill = "lightgray", @@ -174,10 +174,9 @@ autoplot(object, x.title = "Mean of Test and Reference Methods", y.title = "Reference - Test" ) - # Using the default arguments for regression plot -data(creatinine, package = "mcr") -fit <- mcreg( +data("platelet") +fit <- mcreg2( x = platelet$Comparative, y = platelet$Candidate, method.reg = "Deming", method.ci = "jackknife" ) @@ -194,5 +193,5 @@ autoplot(fit, \seealso{ \code{\link[=h_difference]{h_difference()}} to see the type details. -\code{\link[mcr:mcreg]{mcr::mcreg()}} to see the regression parameters. +\linkS4class{MCR} or \code{\link[mcr:mcreg]{mcr::mcreg()}} to see the regression parameters. } diff --git a/man/mcreg.Rd b/man/mcreg.Rd index 108c70e..c1c3018 100644 --- a/man/mcreg.Rd +++ b/man/mcreg.Rd @@ -2,9 +2,12 @@ % Please edit documentation in R/mcr.R \name{mcreg} \alias{mcreg} +\alias{mcreg2} \title{Comparison of Two Measurement Methods Using Regression Analysis} \usage{ mcreg(...) + +mcreg2(...) } \arguments{ \item{...}{ @@ -67,6 +70,12 @@ fit <- mcreg( ) printSummary(fit) getCoefficients(fit) + +# use `MCR` class instead of `MCResult` class in `mcr` package +mcreg2( + x = platelet$Comparative, y = platelet$Candidate, + method.reg = "Deming", method.ci = "jackknife" +) } \seealso{ \code{\link[mcr:mcreg]{mcr::mcreg()}} diff --git a/man/platelet.Rd b/man/platelet.Rd index 19b02d5..370c312 100644 --- a/man/platelet.Rd +++ b/man/platelet.Rd @@ -22,7 +22,7 @@ platelet \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} This example \code{\link{platelet}} can be used to create a data set comparing -Platelet results from two analyzers in cells/μL. +Platelet results from two analyzers in cells. } \seealso{ \link[mcr:creatinine]{mcr::creatinine} that contains data with with serum and plasma diff --git a/revdep/.gitignore b/revdep/.gitignore new file mode 100644 index 0000000..111ab32 --- /dev/null +++ b/revdep/.gitignore @@ -0,0 +1,7 @@ +checks +library +checks.noindex +library.noindex +cloud.noindex +data.sqlite +*.html diff --git a/tests/testthat/test-autoplot.R b/tests/testthat/test-autoplot.R index 4d65a49..d09eeea 100644 --- a/tests/testthat/test-autoplot.R +++ b/tests/testthat/test-autoplot.R @@ -33,7 +33,7 @@ test_that("autoplot works as expected for BAsummary class with multiple argument test_that("autoplot works as expected for MCResult class with default arguments", { data(creatinine, package = "mcr") - object <- mcreg( + object <- mcreg2( x = platelet$Comparative, y = platelet$Candidate, method.reg = "Deming", method.ci = "jackknife" ) @@ -44,7 +44,7 @@ test_that("autoplot works as expected for MCResult class with default arguments" test_that("autoplot works as expected for MCResult class with multiple arguments", { data(creatinine, package = "mcr") - object <- mcreg( + object <- mcreg2( x = platelet$Comparative, y = platelet$Candidate, method.reg = "PaBa", method.ci = "bootstrap" ) diff --git a/vignettes/mcradds.Rmd b/vignettes/mcradds.Rmd index d7f0020..760107d 100644 --- a/vignettes/mcradds.Rmd +++ b/vignettes/mcradds.Rmd @@ -132,7 +132,7 @@ head(qualData) In this scenario, you'd better define the `formula` with candidate assay first, followed by comparative assay to the right of formula, such as right of `~`. If not, you should add the `dimname` argument to indicate which the row and column names 2x2 contingency table, and then define the order of levels you prefer to. ```{r} -tb <- qualData %>% +tb <- qualData %>% diagTab( formula = ~ CandidateN + ComparativeN, levels = c(1, 0) @@ -191,7 +191,7 @@ Regression agreement is a very important criteria in method comparison trials th ```{r} # Deming regression fit <- mcreg( - x = platelet$Comparative, y = platelet$Candidate, + x = platelet$Comparative, y = platelet$Candidate, error.ratio = 1, method.reg = "Deming", method.ci = "jackknife" ) printSummary(fit) @@ -359,7 +359,7 @@ tb1 <- reader %>% levels = c("Positive", "Negative"), rep = TRUE, across = "Site" -) + ) getAccuracy(tb1, ref = "bnr", rng.seed = 12306) ``` @@ -374,7 +374,7 @@ tb2 <- read %>% levels = c("Positive", "Negative"), rep = TRUE, across = "Sample" -) + ) getAccuracy(tb2, ref = "bnr", rng.seed = 12306) ``` @@ -389,7 +389,7 @@ tb3 <- site %>% levels = c("Positive", "Negative"), rep = TRUE, across = "Sample" -) + ) getAccuracy(tb2, ref = "bnr", rng.seed = 12306) ``` @@ -426,21 +426,21 @@ Add more drawing arguments if you would like to adjust the format. More detailed ```{r} autoplot( - object, - type = "absolute", - jitter = TRUE, - fill = "lightblue", - color = "grey", - size = 2, - ref.line.params = list(col = "grey"), - loa.line.params = list(col = "grey"), - label.digits = 2, - label.params = list(col = "grey", size = 3, fontface = "italic"), - x.nbreak = 6, - main.title = "Bland-Altman Plot", - x.title = "Mean of Test and Reference Methods", - y.title = "Reference - Test" - ) + object, + type = "absolute", + jitter = TRUE, + fill = "lightblue", + color = "grey", + size = 2, + ref.line.params = list(col = "grey"), + loa.line.params = list(col = "grey"), + label.digits = 2, + label.params = list(col = "grey", size = 3, fontface = "italic"), + x.nbreak = 6, + main.title = "Bland-Altman Plot", + x.title = "Mean of Test and Reference Methods", + y.title = "Reference - Test" +) ``` ### Regression plot @@ -448,7 +448,7 @@ autoplot( To generate the regression plot, you should create the object from `mcreg()` function and then call `autoplot` straightforward. ```{r} -fit <- mcreg( +fit <- mcreg2( x = platelet$Comparative, y = platelet$Candidate, method.reg = "PaBa", method.ci = "bootstrap" )