Skip to content

Commit

Permalink
add MCR class to relace MCResult in case of mcr is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
kaigu1990 committed Sep 22, 2023
1 parent bb57bb5 commit d961099
Show file tree
Hide file tree
Showing 16 changed files with 172 additions and 46 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -34,6 +33,7 @@ Imports:
Suggests:
dplyr,
knitr,
mcr,
rmarkdown,
spelling,
testthat (>= 3.0.0),
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -35,7 +36,6 @@ exportMethods(getAccuracy)
exportMethods(getOutlier)
import(checkmate)
import(ggplot2)
import(mcr)
import(methods)
importFrom(DescTools,BinomCI)
importFrom(VCA,VCAinference)
Expand Down
21 changes: 10 additions & 11 deletions R/autoplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
#' )
Expand All @@ -326,7 +325,7 @@ setMethod(
#' )
setMethod(
f = "autoplot",
signature = c("MCResult"),
signature = c("MCR"),
definition = function(object,
color = "black",
fill = "lightgray",
Expand All @@ -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)
Expand All @@ -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))
Expand Down Expand Up @@ -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")
)
Expand Down
20 changes: 20 additions & 0 deletions R/mcr.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 ----

Expand Down
1 change: 0 additions & 1 deletion R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#'
"_PACKAGE"

#' @import mcr
#' @import checkmate
#' @import ggplot2
#' @import methods
Expand Down
45 changes: 45 additions & 0 deletions R/pkg_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ reference:
- BAsummary
- RefInt
- tpROC
- MCR
- title: Internal Helper Functions
contents:
- cat_with_newline
Expand Down
2 changes: 2 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ ananlysis
apa
ci
clopper
coef
confInt
creatinin
dL
Expand All @@ -81,6 +82,7 @@ lipoprotein
loa
magrittr
mcr
mnames
nlr
npa
npv
Expand All @@ -97,6 +99,7 @@ quasilinear
quations
refInt
refROC
regmeth
regmethod
repo
reproducibility
Expand Down
42 changes: 42 additions & 0 deletions man/MCR-class.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions man/autoplot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions man/mcreg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/platelet.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions revdep/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
checks
library
checks.noindex
library.noindex
cloud.noindex
data.sqlite
*.html
4 changes: 2 additions & 2 deletions tests/testthat/test-autoplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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"
)
Expand Down
Loading

0 comments on commit d961099

Please sign in to comment.