Skip to content

Commit

Permalink
After merge to developer
Browse files Browse the repository at this point in the history
Cleaning up; can I reduce replication of mean square code?
  • Loading branch information
dpc10ster committed Nov 15, 2023
1 parent 3669af2 commit d202078
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 139 deletions.
4 changes: 2 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ title: "NEWS"


### TODOs 10/4/23
* Insert tests for all failure brances in `isValidDataset`
* Insert tests for all failure branches in `isValidDataset`
* Renamed `UtilVarComponentOR` to `UtilOrVarCov`
* Renamed `UtilVarComponentsDBM` to `UtilDBMVarComp`
* Shorten this log and keep details in a new file, `CodeChangesLog.md`
* Shorten this log and keep details in a new file, `CodeChangesLog.md`, but this has to be outside this package directory



Expand Down
90 changes: 46 additions & 44 deletions R/UtilFigureOfMerit.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#' Calculate empirical figures of merit (FOMs) for factorial dataset, standard
#' or cross-modality
#' one-treatment or two-treatment cross-modality
#'
#' @description Calculate the specified empirical figure of merit for each
#' modality-reader combination in a standard or cross-modality dataset
#' modality-reader combination in a standard (1T) or cross-modality (2T) dataset
#'
#' @param dataset The dataset to be analyzed, \code{\link{RJafroc-package}}
#'
Expand All @@ -11,64 +11,66 @@
#' @param FPFValue Only needed for \code{LROC} data \strong{and} FOM = "PCL" or "ALROC";
#' where to evaluate a partial curve based figure of merit. The default is 0.2.
#'
#' @return For standard dataset: A \code{c(I, J)} dataframe, where the row names are
#' \code{modalityID}'s of the treatments and column names are the
#' \code{readerID}'s of the readers.
#' For cross-modality dataset: Two data frames are returned:
#' * \code{c(I2, J)} data frame, FOMs averaged over the first modality, where the row
#' names are modality IDS of the second modality
#' * \code{c(I1, J)} data frames, FOMs averaged over the second modality, where the row
#' names are modality IDs of the first modality,
#' * In either case the column names are the \code{readerID}'s.
#' @return For standard IT dataset: A \code{c(I, J)} dataframe, where the row
#' names are \code{modalityID}'s of the treatments and column names are the
#' \code{readerID}'s of the readers. For cross-modality dataset: A \code{list}
#' containing two data frames are returned:
#' * \code{c(I2, J)} data frame, FOMs averaged over the first modality,
#' where the row names are modality IDS of the second modality
#' * \code{c(I1, J)} data frames, FOMs averaged over the second modality,
#' where the row names are modality IDs of the first modality,
#' * For either 1T or 2T the column names are the \code{readerID}'s.

#'
#' @details The allowed FOMs depend on the \code{dataType} field of the
#' \code{dataset} object.
#'
#'
#' \strong{For \code{dataset$descriptions$type = "ROC"} only \code{FOM = "Wilcoxon"} is allowed}.
#' \strong{For \code{dataset$descriptions$type = "FROC"} the following FOMs are allowed}:
#' \itemize{
#' \item \code{FOM = "AFROC1"} (use only if no normal cases are available)
#' \item \code{FOM = "AFROC"}
#' \item \code{FOM = "wAFROC1"} (use only if no normal cases are available)
#' \item \code{FOM = "wAFROC"} (the default)
#' \item \code{FOM = "HrAuc"}
#' \item \code{FOM = "HrSe"} (example of an end-point based FOM)
#' \item \code{FOM = "HrSp"} (do:)
#' \item \code{FOM = "MaxLLF"} (do:)
#' \item \code{FOM = "MaxNLF"} (do:)
#' \item \code{FOM = "MaxNLFAllCases"} (do:)
#' \code{dataset} object.
#'
#'
#' \strong{For \code{dataset$descriptions$type = "ROC"} only \code{FOM = "Wilcoxon"} is allowed}.
#' \strong{For \code{dataset$descriptions$type = "FROC"} the following FOMs are allowed}:
#' \itemize{
#' \item \code{FOM = "AFROC1"} (use only if no non-diseased cases are available)
#' \item \code{FOM = "AFROC"}
#' \item \code{FOM = "wAFROC1"} (use only if no non-diseased cases are available)
#' \item \code{FOM = "wAFROC"} (the default)
#' \item \code{FOM = "HrAuc"}
#' \item \code{FOM = "HrSe"} (example of an end-point based FOM)
#' \item \code{FOM = "HrSp"} (do:)
#' \item \code{FOM = "MaxLLF"} (do:)
#' \item \code{FOM = "MaxNLF"} (do:)
#' \item \code{FOM = "MaxNLFAllCases"} (do:)
#' }
#' \code{"MaxLLF"}, \code{"MaxNLF"} and \code{"MaxNLFAllCases"}
#' correspond to ordinate, and abscissa, respectively, of the highest point
#' on the FROC operating characteristic obtained by counting all the marks.
#' Given the number of FOMs possible with FROC data, it is appropriate
#' to make a recommendation: \strong{it is recommended the wAFROC FOM be used
#' whenever possible. One should use the wAFROC1 FOM only if the dataset has
#' no non-diseased cases}.
#' \code{"MaxLLF"}, \code{"MaxNLF"} and \code{"MaxNLFAllCases"}
#' correspond to ordinate, and abscissa, respectively, of the highest point
#' on the FROC operating characteristic obtained by counting all the marks.
#' Given the number of FOMs possible with FROC data, it is appropriate
#' to make a recommendation: \strong{it is recommended the wAFROC FOM be used
#' whenever possible. One should use the wAFROC1 FOM only if the dataset has
#' no non-diseased cases}.
#'
#' For \strong{\code{dataType = "ROI"} dataset only \code{FOM = "ROI"} is allowed}.
#' For \strong{\code{dataType = "ROI"} dataset only \code{FOM = "ROI"} is allowed}.
#'
#' For \strong{\code{dataType = "LROC"}} dataset the following FOMs are allowed:
#' \itemize{
#' \item \code{FOM = "Wilcoxon"} for ROC data inferred from LROC data
#' \item \code{FOM = "PCL"} the probability of correct localization at specified \code{FPFValue}
#' \item \code{FOM = "ALROC"} the area under the LROC from zero to specified \code{FPFValue}
#' }
#' \code{FPFValue} The FPF at which to evaluate \code{PCL} or \code{ALROC};
#' the default is 0.2; only needed for LROC data.
#' For cross-modality analysis ROI and LROC datasets are not supported.
#' For \strong{\code{dataType = "LROC"}} dataset the following FOMs are allowed:
#' \itemize{
#' \item \code{FOM = "Wilcoxon"} for ROC data inferred from LROC data
#' \item \code{FOM = "PCL"} the probability of correct localization at specified \code{FPFValue}
#' \item \code{FOM = "ALROC"} the area under the LROC from zero to specified \code{FPFValue}
#' }
#' \code{FPFValue} The FPF at which to evaluate \code{PCL} or \code{ALROC};
#' the default is 0.2; only needed for LROC data.
#' For cross-modality analysis ROI and LROC datasets are not supported.
#'
#'
#' @examples
#'
#' res <- UtilFigureOfMerit(dataset02, FOM = "Wilcoxon") # ROC data
#' res <- UtilFigureOfMerit(dataset01) # FROC dataset, default wAFROC FOM
#' res <- UtilFigureOfMerit(datasetXModality, FOM = "wAFROC")
#'
#'
#'
#' @references
#'
#' Chakraborty DP (2017) \emph{Observer Performance Methods for Diagnostic Imaging - Foundations,
#' Modeling, and Applications with R-Based Examples}, CRC Press, Boca Raton, FL.
#' \url{https://www.routledge.com/Observer-Performance-Methods-for-Diagnostic-Imaging-Foundations-Modeling/Chakraborty/p/book/9781482214840}
Expand Down
8 changes: 4 additions & 4 deletions R/UtilMeanSquares.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
#' @param method The method, in which the mean squares are calculated. The two
#' valid choices are \code{"DBM"} (default) and \code{"OR"}.
#' @param FPFValue Only needed for \code{LROC} data \strong{and} FOM = "PCL" or "ALROC";
#' where to evaluate a partial curve based figure of merit. The default is 0.2.
#' where to evaluate a partial curve based figure of merit. The default is 0.2.
#'
#' @return A list containing the mean squares
#'
#' @details
#' For \code{DBM} method, \code{msT, msTR, msTC, msTRC} will not be available
#' if the dataset contains only one modality. Similarly,
#' \code{msR, msTR, msRC, msTRC} will not be returned for single reader dataset.
#' if the dataset contains only one modality (NAs are returned). Similarly,
#' \code{msR, msTR, msRC, msTRC} NAs are returned for single reader dataset.
#' For \code{ORH} method, \code{msT, msR, msTR} will be returned for multiple
#' reader multiple modality dataset. \code{msT} is not available for single
#' modality dataset, and \code{msR} is not available for single reader dataset.
#' modality dataset and \code{msR} is not available for single reader dataset.
#'
#' @examples
#' result <- UtilMeanSquares(dataset02, FOM = "Wilcoxon")
Expand Down
72 changes: 37 additions & 35 deletions R/UtilORVarComp.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
#' Obuchowski-Rockette variance components for dataset
#'
#' @param dataset Factorial or cross-modality dataset
#' @param dataset Factorial one-treatment or cross-modality two-treatment dataset
#'
#' @param FOM Figure of merit
#'
#' @param covEstMethod The covariance estimation method, "jackknife"
#' (the default) or "bootstrap" or "DeLong" ("DeLong" is applicable only for
#' FOM = "Wilcoxon").
#'
#' @param FPFValue Only needed for \code{LROC} data \strong{and} FOM = "PCL" or "ALROC":
#' the \code{FPFValue} at which to evaluate a partial curve based figure of merit.
#' The default is \code{FPFValue} = 0.2.
#' @param FPFValue Only needed for \code{LROC} data \strong{and} FOM = "PCL"
#' or "ALROC": the \code{FPFValue} at which to evaluate a partial curve
#' based figure of merit. The default is 0.2.
#'
#' @param nBoots The number of bootstraps (default = 200).Only needed for covEstMethod = "bootstrap".
#' @param nBoots The number of bootstraps (default 200).Only needed for
#' covEstMethod = "bootstrap".
#'
#' @param seed Only needed for the bootstrap covariance estimation method. The initial
#' seed for the random number generator, the default is \code{NULL}, for random seed.
#' @param seed Only needed for the bootstrap covariance estimation method.
#' The initial seed for the random number generator, the default is
#' \code{NULL}, for random seed.
#'
#' @return A list containing the following \code{data.frames}:
#' \itemize{
Expand Down Expand Up @@ -44,11 +46,11 @@
#' @export
#'
UtilORVarComp <- function (dataset,
FOM,
covEstMethod = "jackknife",
FPFValue = 0.2,
nBoots = 200,
seed = NULL)
FOM,
covEstMethod = "jackknife",
FPFValue = 0.2,
nBoots = 200,
seed = NULL)
{

if (dataset$descriptions$design == "FCTRL") {
Expand All @@ -61,21 +63,21 @@ UtilORVarComp <- function (dataset,
jkFomValues <- UtilPseudoValues(dataset, FOM, FPFValue)$jkFomValues

VarCovOR <- SmpldFom2ORCov(jkFomValues,
modalityID,
readerID,
covEstMethod,
FPFValue,
nBoots,
seed)
modalityID,
readerID,
covEstMethod,
FPFValue,
nBoots,
seed)

Output <- OROutput(foms,
VarCovOR,
modalityID,
readerID)
VarCovOR,
modalityID,
readerID)

} else {
# cross-modality factorial dataset, two treatment factors

modalityID1 <- dataset$descriptions$modalityID1
modalityID2 <- dataset$descriptions$modalityID2
modalityID <- list(modalityID2, modalityID1)
Expand All @@ -87,15 +89,15 @@ UtilORVarComp <- function (dataset,
jkFomValues <- UtilPseudoValues(dataset, FOM, FPFValue)$jkFomValues

VarCovOR <- SmpldFom2ORCov(jkFomValues,
modalityID,
readerID,
covEstMethod,
FPFValue,
nBoots,
seed)
modalityID,
readerID,
covEstMethod,
FPFValue,
nBoots,
seed)

Output <- OROutput(foms, VarCovOR, modalityID, readerID)

}
return(Output)
}
Expand All @@ -104,12 +106,12 @@ UtilORVarComp <- function (dataset,


SmpldFom2ORCov <- function(jkFomValues,
modalityID,
readerID,
covEstMethod,
FPFValue,
nBoots,
seed)
modalityID,
readerID,
covEstMethod,
FPFValue,
nBoots,
seed)
{

if (covEstMethod == "jackknife") {
Expand Down
92 changes: 48 additions & 44 deletions man/UtilFigureOfMerit.Rd

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

Loading

0 comments on commit d202078

Please sign in to comment.