From d29969adfd991557c13d8dd154880577a129ae87 Mon Sep 17 00:00:00 2001 From: Brandon Gallas Date: Fri, 25 Oct 2024 10:45:31 -0400 Subject: [PATCH] Add utility function to convert different data formats. --- Rpackage/iMRMC/NAMESPACE | 1 + Rpackage/iMRMC/R/utilityFunctions.R | 59 +++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/Rpackage/iMRMC/NAMESPACE b/Rpackage/iMRMC/NAMESPACE index 6141d86f..13377f1a 100644 --- a/Rpackage/iMRMC/NAMESPACE +++ b/Rpackage/iMRMC/NAMESPACE @@ -1,5 +1,6 @@ # Generated by roxygen2: do not edit by hand +export(convertDF) export(convertDFtoDesignMatrix) export(convertDFtoScoreMatrix) export(createGroups) diff --git a/Rpackage/iMRMC/R/utilityFunctions.R b/Rpackage/iMRMC/R/utilityFunctions.R index b7ee0762..a9997c65 100644 --- a/Rpackage/iMRMC/R/utilityFunctions.R +++ b/Rpackage/iMRMC/R/utilityFunctions.R @@ -1,3 +1,62 @@ +## convertDF #### +#' Convert MRMC data frames +#' +#' @param inDF An MRMC dataframe with reading study results in \code{inDFtype} format +#' @param inDFtype A string indicating the format type of the input MRMC data frame +#' @param outDFtype A string indicating the format type of the output MRMC data frame. +#' @param readers A character array holding the column names (readerIDs) corresponding to the data from different readers +#' +#' @return An MRMC dataframe with reading study results in \code{outDFtype} format +#' @export +#' @details +#' MRMC data frames contain scores from readers, cases, and sometimes modalities. This packages deals with (currently) +#' two MRMC data frame formats. These are the formats: +#' \describe{ +#' \item{matrixMode}{ +#' For this format, each row contains all the information for a case, +#' including the reader study result for several readers, ground truth and other information as seperate columns. +#' This mode can only hold data from one modality. +#' } +#' \item{listMode}{ +#' For this format, each row contains the data for one observation. The columns +#' specify the readerID, caseID, score, ground truth, and other information if there is any. +#' This mode can hold data from multiple modalities. +#' } +#' } +#' +#' +#' @export +#' +# @examples +convertDF <- function(inDF, inDFtype, outDFtype, readers){ + + if (inDFtype == "matrixMode" & outDFtype == "listMode") { + + # Split the data frame by columns, with and without the readers + dfReaders <- inDF[ , (colnames(inDF) %in% readers)] + dfNoReaders <- inDF[ , !(colnames(inDF) %in% readers)] + + # Replicate the data without readers while adding the data for each reader + outDF <- data.frame() + for (iReader in readers) { + + # Start with the data frame with no readers + tempDF <- dfNoReaders + # Add a column "readerID" and assign it the reader name + tempDF$readerID <- iReader + # Add a column "score" and assign it the scores of the current reader + tempDF$score <- dfReaders[ , iReader] + # Aggregate the reader data into the output data frame + outDF <- rbind(outDF, tempDF) + + } + + return(outDF) + + } + +} + ## createIMRMCdf #### #' Convert a data frame with all needed factors to doIMRMC formatted data frame #'