### Example: SimulateCorCbmDataset() Source: https://dpc10ster.github.io/RJafroc/reference/SimulateCorCbmDataset.html Example usage of SimulateCorCbmDataset with default parameters. The commented-out code shows a long-running example with K1=5000 and K2=5000, which is not run by default. ```r dataset <- SimulateCorCbmDataset() # \donttest{ ## this takes very long ## dataset <- SimulateCorCbmDataset(K1 = 5000, K2 = 5000) # } ``` -------------------------------- ### Example usage of DfCreateCorCbmDataset Source: https://dpc10ster.github.io/RJafroc/reference/DfCreateCorCbmDataset.html Creates a dataset with default parameters. The commented lines show how to set a seed and a long-running example. ```R ## seed <- 1 ## this gives unequal numbers of bins in X and Y conditions for 50/50 dataset dataset <- DfCreateCorCbmDataset() # \donttest{ ## this takes very long time!! used to show asymptotic convergence of ML estimates ## dataset <- DfCreateCorCbmDataset(K1 = 5000, K2 = 5000) # } ``` -------------------------------- ### Example: OR-based algorithm with pilot dataset Source: https://dpc10ster.github.io/RJafroc/reference/SsPowerGivenJK.html A simple example using the default OR method with a pilot dataset. This is the default behavior when method is not specified. ```r ## EXAMPLE 3: specify 2-modality ROC dataset and use OR-based alg. res <- SsPowerGivenJK(dataset = dataset02, FOM = "Wilcoxon", effectSize = 0.05, J = 6, K = 251) ``` -------------------------------- ### Examples: RRRC, FRRC, RRFC power calculations Source: https://dpc10ster.github.io/RJafroc/reference/SsPowerGivenJK.html Three examples showing how to compute power for different analysis options (RRRC, FRRC, RRFC) using a pilot dataset and forcing the DBM algorithm with UseDBMHB2004 = TRUE. Each example sets the same parameters but changes analysisOption. ```r ## EXAMPLE 1: RRRC power ## specify 2-modality ROC dataset and force DBM alg. res <- SsPowerGivenJK(dataset = dataset02, FOM = "Wilcoxon", effectSize = 0.05, J = 6, K = 251, method = "DBM", UseDBMHB2004 = TRUE) # RRRC is default ## EXAMPLE 1A: FRRC power res <- SsPowerGivenJK(dataset = dataset02, FOM = "Wilcoxon", effectSize = 0.05, J = 6, K = 251, method = "DBM", UseDBMHB2004 = TRUE, analysisOption = "FRRC") ## EXAMPLE 1B: RRFC power res <- SsPowerGivenJK(dataset = dataset02, FOM = "Wilcoxon", effectSize = 0.05, J = 6, K = 251, method = "DBM", UseDBMHB2004 = TRUE, analysisOption = "RRFC") ``` -------------------------------- ### SsFrocSampleSize example with dataset04 Source: https://dpc10ster.github.io/RJafroc/reference/SsFrocSampleSize.html Example call to SsFrocSampleSize using a subset of dataset04, with effectSizeROC 0.03, 5 readers, 100 cases, and a lesion distribution. The example is wrapped in \donttest{} and includes timing output. ```r # \donttest{ ## Examples with CPU or elapsed time > 5s ## user system elapsed ## SsFrocSampleSize 8.102 0.023 8.135 ## SsFrocSampleSize(DfExtractDataset(dataset04, trts = c(1,2)), ## effectSizeROC = 0.03, JPivot = 5, KPivot = 100, lesDistr = c(0.69, 0.2, 0.11)) # } ``` -------------------------------- ### Example: Save dataset05 to rocData2.xlsx Source: https://dpc10ster.github.io/RJafroc/reference/DfWriteExcelDataFile.html Example call to DfWriteExcelDataFile that saves the dataset05 object to an Excel file named 'rocData2.xlsx'. The example is wrapped in \donttest{} and commented out with #. ```r # \donttest{ ##DfWriteExcelDataFile(dataset = dataset05, fileName = "rocData2.xlsx") # } ``` -------------------------------- ### SimulateFrocDataset example with plotting Source: https://dpc10ster.github.io/RJafroc/reference/SimulateFrocDataset.html Example that sets parameters, calls SimulateFrocDataset to generate a dataset, and then plots empirical FROC operating characteristics using PlotEmpOpChrs. The seed is set to 1 for reproducibility. ```r set.seed(1) K1 <- 5;K2 <- 7; maxLL <- 2;perCase <- floor(runif(K2, 1, maxLL + 1)) mu <- 1;lambda <- 1;nu <- 0.99 ;zeta1 <- -1 I <- 2; J <- 5 frocDataRaw <- SimulateFrocDataset( mu = mu, lambda = lambda, nu = nu, zeta1 = zeta1, I = I, J = J, K1 = K1, K2 = K2, perCase = perCase ) ## plot the data ret <- PlotEmpOpChrs(frocDataRaw, opChType = "FROC") ## print(ret$Plot) ``` -------------------------------- ### Examples: Extract paired data with DfExtractCorCbmDataset Source: https://dpc10ster.github.io/RJafroc/reference/DfExtractCorCbmDataset.html Three example calls showing different ways to specify treatments and readers: two readers in the first modality, one reader across two treatments, and two readers across two treatments. The examples are wrapped in \donttest{}. ```R # \donttest{ ## Extract the paired data corresponding to the second and third readers in the first modality ## from the included ROC dataset dataset11_23 <- DfExtractCorCbmDataset(dataset05, trts = 1, rdrs = c(2,3)) ## Extract the paired data corresponding to the third reader in the first and second treatments dataset12_33 <- DfExtractCorCbmDataset(dataset05, trts = c(1,2), rdrs = 3) ## Extract the data corresponding to the first reader in the first ## modality paired with the data ## from the third reader in the second modality ## (the bin indices are at different positions in the two arrays) dataset12_13 <- DfExtractCorCbmDataset(dataset05, trts = c(1,2), rdrs = c(1,3)) # } ``` -------------------------------- ### St usage examples Source: https://dpc10ster.github.io/RJafroc/reference/St.html Demonstrates calling St with different datasets, FOMs, and methods. The first three lines show basic usage; the last two are wrapped in \donttest{} to avoid running in examples. ```r result <- St(dataset02,FOM = "Wilcoxon", method = "DBM") result <- St(dataset02,FOM = "Wilcoxon", method = "OR") result <- St(datasetX, FOM = "wAFROC", method = "OR", analysisOption = "RRRC") # \donttest{ result <- St(dataset05, FOM = "wAFROC") result <- St(dataset05, FOM = "HrAuc", method = "DBM") # } ``` -------------------------------- ### UtilORVarComp example with jackknife and wAFROC Source: https://dpc10ster.github.io/RJafroc/reference/UtilORVarComp.html Example usage of UtilORVarComp with the default jackknife method for FOM 'Wilcoxon' on dataset02, and with FOM 'wAFROC' on datasetX. The commented lines show alternative bootstrap and DeLong calls. ```r ## use the default jackknife for covEstMethod vc <- UtilORVarComp(dataset02, FOM = "Wilcoxon") ##UtilORVarComp(dataset02, FOM = "Wilcoxon", covEstMethod = "bootstrap", ##nBoots = 2000, seed = 100)$VarCom ##UtilORVarComp(dataset02, FOM = "Wilcoxon", covEstMethod = "DeLong")$VarCom vc <- UtilORVarComp(datasetX, FOM = "wAFROC") ``` -------------------------------- ### Install required R packages Source: https://dpc10ster.github.io/RJafroc/index.html Use this command at the R Console to install the first two packages listed under Imports in the DESCRIPTION file. ```R install.packages(c("openxlsx", "ggplot2")) ``` -------------------------------- ### RSM_wLLF example call Source: https://dpc10ster.github.io/RJafroc/reference/RSM_wLLF.html Example call to RSM_wLLF with sample parameters. The output is 0.34174. ```r RSM_wLLF(1, 1, 0.9, lesDistr = c(0.5, 0.4, 0.1), relWeights = c(0.7, 0.2, 0.1)) #> [1] 0.34174 ## 0.34174 ``` -------------------------------- ### R example: run doBootstrap with parametricFOM=TRUE Source: https://dpc10ster.github.io/RJafrocBook/sources-of-variability.html Sets up the input data and calls `doBootstrap` with `parametricFOM=TRUE`, `B=200`, `seed=1`. The output shows the original AUC, mean bootstrap AUC, and standard deviation. The example uses a 2x5 counts table. ```R parametricFOM <- TRUE B <- 200;seed <- 1;set.seed(seed) RocTable = array(dim = c(2,5)) RocTable[1,] <- c(30,19,8,2,1) RocTable[2,] <- c(5,6,5,12,22) ret <- doBootstrap(parametricFOM, B, seed, RocTable) OrigAUC <- ret$OrigAUC meanAUCboot <- ret$meanAUCboot stdAUCboot <- ret$stdAUCboot cat("Bootstrap variance estimation:", "\nparametricFOM = ", parametricFOM, "\nseed = ", seed, "\nB = ", B, "\nOrigAUC = ", OrigAUC, "\nmeanAUCboot = ", meanAUCboot, "\nstdAUCboot = ", stdAUCboot, "\n") ``` ```R #> Bootstrap variance estimation: #> parametricFOM = TRUE #> seed = 1 #> B = 200 #> OrigAUC = 0.8704519 #> meanAUCboot = 0.8671713 #> stdAUCboot = 0.04380523 ``` -------------------------------- ### UtilLesDistr examples with dataset01, dataset02, datasetCadLroc, array, and dataset11 Source: https://dpc10ster.github.io/RJafroc/reference/UtilLesDistr.html Five examples showing the output of UtilLesDistr for different inputs: an FROC dataset (dataset01), an ROC dataset (dataset02), an LROC dataset (datasetCadLroc), a custom 1D-array, and a large FROC dataset (dataset11). Each example includes the resulting data frame and comments explaining the output. ```r res <- UtilLesDistr(dataset01) # FROC dataset ## lesID Freq ## 1 1 0.93258427 ## 2 2 0.06741573 ## In the Excel input file, 93 percent of lesions have lesionID = 1 ## and the rest have lesionID = 2 res <- UtilLesDistr(dataset02) # ROC dataset ## lesID Freq ## 1 1 1 ## In the Excel input file all dis. cases have one lesion res <- UtilLesDistr(datasetCadLroc) # LROC dataset ## lesID Freq ## 1 1 1 ## In the Excel input file all dis. cases have one lesion res <- UtilLesDistr(c(0.5, 0.3, 0.1, 0.1)) ## lesID Freq ## 1 1 0.5 ## 2 2 0.3 ## 3 3 0.1 ## 4 4 0.1 ## An example of array input; 50 percent of the cases have lesionID = 1, ## 30 percent have lesionID = 2, etc. res <- UtilLesDistr(dataset11) ## big froc dataset ## lesID Freq ## 1 1 0.217391304 ## 2 2 0.200000000 ## 3 3 0.113043478 ## 4 4 0.086956522 ## 5 5 0.043478261 ## 6 6 0.095652174 ## 7 7 0.052173913 ## 8 8 0.069565217 ## 9 9 0.017391304 ## 10 10 0.026086957 ## 11 11 0.026086957 ## 12 12 0.026086957 ## 16 16 0.017391304 ## 20 20 0.008695652 ## TBA!! This dataset has lots of lesions (3D imaging for lung cancer). ## The lesionIDs range from 1 to 20 with a few missing, ## e.g., lesionID = 13 is not present in any diseased case. ## Cases with lesionID = 1 have frequency 0.217, those with lesionID = 16 ## have frequency 0.174, those with lesionID = 20 have frequency 0.00870, etc. ``` -------------------------------- ### DfSaveDataFile usage examples Source: https://dpc10ster.github.io/RJafroc/reference/DfSaveDataFile.html Commented examples of saving dataset02 in MRMC and iMRMC formats with different file extensions and data descriptions. ```r # \donttest{ ## DfSaveDataFile(dataset = dataset02, ## fileName = "rocData2.csv", format = "MRMC") ## DfSaveDataFile(dataset = dataset02, ## fileName = "rocData2.lrc", format = "MRMC", ## dataDescription = "ExampleROCdata1") ## DfSaveDataFile(dataset = dataset02, ## fileName = "rocData2.txt", format = "MRMC", ## dataDescription = "ExampleROCdata2") ## DfSaveDataFile(dataset = dataset02, ## fileName = "dataset05.imrmc", format = "iMRMC", ## dataDescription = "ExampleROCdata3") # } ``` -------------------------------- ### UtilPseudoValues example calls with wAFROC FOM Source: https://dpc10ster.github.io/RJafroc/reference/UtilPseudoValues.html Two example calls: the first extracts the first 10 jackknife FOM values for dataset05, the second computes pseudovalues for datasetX. Both use FOM = "wAFROC". ```r result <- UtilPseudoValues(dataset05, FOM = "wAFROC")$jkFomValues[1,1,1:10] result <- UtilPseudoValues(datasetX, FOM = "wAFROC") ``` -------------------------------- ### Example: NULL dataset with DBM variance components Source: https://dpc10ster.github.io/RJafroc/reference/SsPowerGivenJK.html Shows how to supply variance components when dataset is NULL. The example uses UtilDBMVarComp to obtain variance components and passes them as a list to the ... argument. Note the comments indicate that the right-hand side values should be replaced with actual values. ```r ## EXAMPLE 2: specify NULL dataset & DBM var. comp. & force DBM-based alg. vcDBM <- UtilDBMVarComp(dataset02, FOM = "Wilcoxon")$VarCom res <- SsPowerGivenJK(dataset = NULL, FOM = "Wilcoxon", J = 6, K = 251, effectSize = 0.05, method = "DBM", UseDBMHB2004 = TRUE, list( VarTR = vcDBM["VarTR","Estimates"], # replace rhs with actual values as in 4A VarTC = vcDBM["VarTC","Estimates"], # do: VarErr = vcDBM["VarErr","Estimates"])) # do: ``` -------------------------------- ### FitBinormalRoc examples with various datasets Source: https://dpc10ster.github.io/RJafroc/reference/FitBinormalRoc.html Examples of fitting the binormal model to different datasets, including an ROC dataset, a binned FROC dataset, single and two interior point data, TONY data, and degenerate ROC data. The examples show how to call the function and print the fitted plot. ```R # \donttest{ ## Test with an included ROC dataset retFit <- FitBinormalRoc(dataset02);## print(retFit$fittedPlot) ## Test with an included FROC dataset; it needs to be binned ## as there are more than 5 discrete ratings levels binned <- DfBinDataset(dataset05, desiredNumBins = 5, opChType = "ROC") retFit <- FitBinormalRoc(binned);## print(retFit$fittedPlot) ## Test with single interior point data fp <- c(rep(1,7), rep(2, 3)) tp <- c(rep(1,5), rep(2, 5)) dataset <- Df2RJafrocDataset(fp, tp) retFit <- FitBinormalRoc(dataset);## print(retFit$fittedPlot) ## Test with two interior data points fp <- c(rep(1,7), rep(2, 5), rep(3, 3)) tp <- c(rep(1,3), rep(2, 5), rep(3, 7)) dataset <- Df2RJafrocDataset(fp, tp) retFit <- FitBinormalRoc(dataset);## print(retFit$fittedPlot) ## Test with TONY data for which chisqr can be calculated ds <- DfFroc2Roc(dataset01) retFit <- FitBinormalRoc(ds, 2, 3);## print(retFit$fittedPlot) ## retFit$ChisqrFitStats ## Test with included degenerate ROC data retFit <- FitBinormalRoc(datasetDegenerate);## print(retFit$fittedPlot) #> Warning: Data is degenerate; binormal model cannot fit it unambiguously: use CBM or RSM method # } ``` -------------------------------- ### SsPowerTable example with OR method Source: https://dpc10ster.github.io/RJafroc/reference/SsPowerTable.html Example of sample size calculation using the OR method. The code is wrapped in a donttest block and includes a comment showing expected CPU/elapsed time. The actual call is commented out. ```r # \donttest{ ## Examples with CPU or elapsed time > 5s ## user system elapsed ## SsPowerTable 20.033 0.037 20.077 ## Example of sample size calculation with OR method ## SsPowerTable(dataset02, FOM = "Wilcoxon", method = "OR") # } ``` -------------------------------- ### Install RJafroc from GitHub Source: https://dpc10ster.github.io/RJafroc/index.html Installs the RJafroc package directly from the dpc10ster GitHub repository using devtools. This triggers compilation of C++ code. ```R install_github("dpc10ster/RJafroc") ``` -------------------------------- ### Output of SsSampleSizeKGivenJ example Source: https://dpc10ster.github.io/RJafrocQuickStart/froc-sample-size.html Output from the SsSampleSizeKGivenJ example call, showing ROC-ES, wAFROC-ES, K80RRRC (number of cases needed for 80% power), and Power-wAFROC. ```r ## ROC-ES = 0.035 , wAFROC-ES = 0.0759268 , K80RRRC = 84 , Power-wAFROC = 0.8023879 ``` -------------------------------- ### Example usage of Util2Intrinsic Source: https://dpc10ster.github.io/RJafroc/reference/Util2Intrinsic.html Example showing how to call Util2Intrinsic with sample values and extract the intrinsic parameters. Note that the physical values are only constrained to be positive, so nu_i is not constrained to be between 0 and 1. ```R mu <- 2;lambda <- 10;nu <- 0.9 lambda_i <- Util2Intrinsic(mu, lambda, nu)$lambda_i nu_i <- Util2Intrinsic(mu, lambda, nu)$nu_i ## note that the physical values are only constrained to be positive, e.g., nu_i is not constrained ## to be between 0 and one. ``` -------------------------------- ### Examples of binning datasets with different operating characteristics Source: https://dpc10ster.github.io/RJafroc/reference/DfBinDataset.html Demonstrates binning various datasets with different desiredNumBins and opChType values. The first block shows binning dataset02 and dataset05 with ROC, AFROC, and wAFROC, and varying bin counts. The second block shows a longer example that simulates an ROC dataset, bins it, and compares figure of merit before and after binning. ```r # \donttest{ binned <- DfBinDataset(dataset02, desiredNumBins = 3, opChType = "ROC") binned <- DfBinDataset(dataset05, desiredNumBins = 4, opChType = "ROC") binned <- DfBinDataset(dataset05, desiredNumBins = 4, opChType = "AFROC") binned <- DfBinDataset(dataset05, desiredNumBins = 4, opChType = "wAFROC") binned <- DfBinDataset(dataset05, opChType = "wAFROC", desiredNumBins = 1) binned <- DfBinDataset(dataset05, opChType = "wAFROC", desiredNumBins = 2) binned <- DfBinDataset(dataset05, opChType = "wAFROC", desiredNumBins = 3) ## etc. # } # \donttest{ ## takes longer than 5 sec on OSX dataset <- SimulateRocDataset(I = 2, J = 5, K1 = 50, K2 = 70, a = 1, b = 0.5, seed = 123) datasetB <- DfBinDataset(dataset, desiredNumBins = 7, opChType = "ROC") fomOrg <- as.matrix(UtilFigureOfMerit(dataset, FOM = "Wilcoxon")) ##print(fomOrg) fomBinned <- as.matrix(UtilFigureOfMerit(datasetB, FOM = "Wilcoxon")) ##print(fomBinned) ##cat("mean, sd = ", mean(fomOrg), sd(fomOrg), "\n") ##cat("mean, sd = ", mean(fomBinned), sd(fomBinned), "\n") # } ``` -------------------------------- ### Example: UtilDBMVarComp with dataset02 and Wilcoxon FOM Source: https://dpc10ster.github.io/RJafroc/reference/UtilDBMVarComp.html Example call to UtilDBMVarComp using dataset02 and FOM = 'Wilcoxon'. The result is stored in a variable named 'result'. ```r result <- UtilDBMVarComp(dataset02, FOM = "Wilcoxon") ``` -------------------------------- ### Example 5A: Compute power with hard-coded DBM variance components Source: https://dpc10ster.github.io/RJafroc/reference/SsPowerGivenJK.html Calls SsPowerGivenJK with method='DBM' and explicit numeric values for KStar, VarR, VarC, VarTR, VarTC, VarRC, and VarErr. This is the hard-coded version of Example 5. ```R res <- SsPowerGivenJK(dataset = NULL, J = 6, K = 251, effectSize = 0.05, method = "DBM", FOM = "Wilcoxon", list(KStar = 114, VarR = 0.00153499935, VarC = 0.02724923428, VarTR = 0.00020040252, VarTC = 0.01197529621, VarRC = 0.01226472859, VarErr = 0.03997160319)) ``` -------------------------------- ### R: kableExtra table with collapse_rows Source: https://dpc10ster.github.io/RJafrocFrocBook/index.html Example of creating a table with kableExtra, using collapse_rows and kable_styling options. ```R kbl(dfA, caption = "….", booktabs = TRUE, escape = FALSE) %>% collapse_rows(columns = c(1, 3), valign = "middle") %>% kable_styling(latex_options = c("basic", "scale_down", "HOLD_position"), row_label_position = "c") ``` -------------------------------- ### RSM_pdfN example with output Source: https://dpc10ster.github.io/RJafroc/reference/RSM_pdfN.html Example call to RSM_pdfN with z = c(1,2) and lambda = 1, producing the density values 0.20647131 and 0.05277653. ```r RSM_pdfN(c(1,2),1) #> [1] 0.20647131 0.05277653 ``` -------------------------------- ### DfReadDataFile examples for reading various data formats Source: https://dpc10ster.github.io/RJafroc/reference/DfReadDataFile.html Demonstrates reading ROC, FROC, and LROC data files in different formats (JAFROC, MRMC, iMRMC). The first example reads an LROC file with newExcelFileFormat=TRUE. The remaining examples are wrapped in \donttest{} and show reading .xlsx, .csv, and .imrmc files. ```r fileName <- system.file("extdata", "toyFiles/ROC/rocCr.xlsx", package = "RJafroc", mustWork = TRUE) rdrArr1D <- DfReadDataFile(fileName, newExcelFileFormat = TRUE) # \donttest{ fileName <- system.file("extdata", "Roc.xlsx", package = "RJafroc", mustWork = TRUE) RocDataXlsx <- DfReadDataFile(fileName) fileName <- system.file("extdata", "RocData.csv", package = "RJafroc", mustWork = TRUE) RocDataCsv<- DfReadDataFile(fileName, format = "MRMC") fileName <- system.file("extdata", "RocData.imrmc", package = "RJafroc", mustWork = TRUE) RocDataImrmc<- DfReadDataFile(fileName, format = "iMRMC") fileName <- system.file("extdata", "Froc.xlsx", package = "RJafroc", mustWork = TRUE) FrocDataXlsx <- DfReadDataFile(fileName, sequentialNames = TRUE) # } ``` -------------------------------- ### Example: Simulate FROC dataset and verify AUC equivalence Source: https://dpc10ster.github.io/RJafroc/reference/SimulateFrocFromLrocDataset.html Example usage of SimulateFrocFromLrocDataset with datasetCadLroc. It computes the LROC AUC and the FROC HrAuc, then uses testthat::expect_equal to verify they are equal. ```R frocDataset <- SimulateFrocFromLrocDataset(datasetCadLroc) lrocAuc <- UtilFigureOfMerit(datasetCadLroc, FOM = "Wilcoxon") frocHrAuc <- UtilFigureOfMerit(frocDataset, FOM = "HrAuc") testthat::expect_equal(lrocAuc, frocHrAuc) ``` -------------------------------- ### Example: Calculate FOMs for ROC, FROC, and cross-modality datasets Source: https://dpc10ster.github.io/RJafroc/reference/UtilFigureOfMerit.html Three example calls: one for ROC data with FOM = "Wilcoxon", one for FROC data using the default wAFROC FOM, and one for a cross-modality dataset with FOM = "wAFROC". ```r res <- UtilFigureOfMerit(dataset02, FOM = "Wilcoxon") # ROC data res <- UtilFigureOfMerit(dataset01) # FROC dataset, default wAFROC FOM res <- UtilFigureOfMerit(datasetX, FOM = "wAFROC") ``` -------------------------------- ### Convert DBM to OR variance components with example output Source: https://dpc10ster.github.io/RJafroc/reference/UtilDBM2ORVarCom.html Example usage of UtilDBM2ORVarCom with dataset02 and Wilcoxon FOM, showing the resulting OR variance components. Also includes a related conversion back using UtilOR2DBMVarCom. ```r DBMVarCom <- St(dataset02, FOM = "Wilcoxon", method = "DBM")$ANOVA$VarCom UtilDBM2ORVarCom(114, DBMVarCom) #> VarCom Rhos #> VarR 0.0015349993 NA #> VarTR 0.0002004025 NA #> Cov1 0.0003466137 0.4320314 #> Cov2 0.0003440748 0.4288668 #> Cov3 0.0002390284 0.2979333 #> Var 0.0008022883 NA ORVarCom <- St(dataset02, FOM = "Wilcoxon", method = "OR")$ANOVA$VarCom UtilOR2DBMVarCom(114, ORVarCom) #> Estimates #> VarR 0.0015349993 #> VarC 0.0272492343 #> VarTR 0.0002004025 #> VarTC 0.0119752962 #> VarRC 0.0122647286 #> VarErr 0.0399716032 ``` -------------------------------- ### Compute pnorm and qnorm for threshold example Source: https://dpc10ster.github.io/RJafrocBook/binary-task-model.html Shows two R examples: pnorm(0.75) returns 0.773, and 2*qnorm(pnorm(zeta)) returns 1.5. These illustrate the relationship between sensitivity, specificity, and the separation parameter. ```R pnorm(0.75) # example 1 #> [1] 0.773 2*qnorm(pnorm(zeta)) # example 2 #> [1] 1.5 ``` -------------------------------- ### RSM_pdfD example with three lesion distribution values Source: https://dpc10ster.github.io/RJafroc/reference/RSM_pdfD.html Example call to RSM_pdfD with z=c(1,2), mu=1, lambda=1, nu=0.5, and lesion distribution c(0.2,0.3,0.5). Output shows pdf values. ```R RSM_pdfD(c(1,2),1,1,0.5, c(0.2, 0.3, 0.5)) #> [1] 0.3636117 0.2830817 ``` -------------------------------- ### UtilMeanSquares usage examples Source: https://dpc10ster.github.io/RJafroc/reference/UtilMeanSquares.html Two example calls: one using the default method "DBM" with FOM = "Wilcoxon" on dataset02, and another using method = "OR" with FOM = "wAFROC" on dataset05. Both assign the result to a variable named 'result'. ```r result <- UtilMeanSquares(dataset02, FOM = "Wilcoxon") result <- UtilMeanSquares(dataset05, FOM = "wAFROC", method = "OR") ``` -------------------------------- ### FitCbmRoc examples with various datasets Source: https://dpc10ster.github.io/RJafroc/reference/FitCbmRoc.html Examples of using FitCbmRoc with included ROC data, degenerate data, single and two interior point data, and data with zero counts. Also shows retrieving the ChisqrFitStats output. ```r # \donttest{ ## CPU time 8.7 sec on Ubuntu (#13) ## Test with included ROC data retFit <- FitCbmRoc(dataset02);## print(retFit$fittedPlot) ## Test with included degenerate ROC data (yes! CBM can fit such data) retFit <- FitCbmRoc(datasetDegenerate);## print(retFit$fittedPlot) ## Test with single interior point data fp <- c(rep(1,7), rep(2, 3)) tp <- c(rep(1,5), rep(2, 5)) dataset <- Df2RJafrocDataset(fp, tp) retFit <- FitCbmRoc(dataset);## print(retFit$fittedPlot) ## Test with two interior data points fp <- c(rep(1,7), rep(2, 5), rep(3, 3)) tp <- c(rep(1,3), rep(2, 5), rep(3, 7)) dataset <- Df2RJafrocDataset(fp, tp) retFit <- FitCbmRoc(dataset); ## print(retFit$fittedPlot) ## Test with included ROC data (some bins have zero counts) retFit <- FitCbmRoc(dataset02, 2, 1);## print(retFit$fittedPlot) ## Test with TONY data for which chisqr can be calculated ds <- DfFroc2Roc(dataset01) retFit <- FitCbmRoc(ds, 2, 3);## print(retFit$fittedPlot) retFit$ChisqrFitStats #> $chisq #> [1] 1.449787 #> #> $pVal #> [1] 0.4843762 #> #> $df #> [1] 2 #> # } ``` -------------------------------- ### Example call to SsSampleSizeKGivenJ with NULL dataset Source: https://dpc10ster.github.io/RJafrocQuickStart/froc-sample-size.html Example call to SsSampleSizeKGivenJ with dataset set to NULL, specifying J=6, effectSize=effectSizewAFROC, and a list of variance components (JStar, KStar, VarTR, Cov1, Cov2, Cov3, Var). Returns the number of cases needed for 80% power. ```r ret2 <- SsSampleSizeKGivenJ( dataset = NULL, J = 6, effectSize = effectSizewAFROC, list(JStar = JStar, KStar = KStar, VarTR = varTR_wafroc, Cov1 = Cov1_wafroc, Cov2 = Cov2_wafroc, Cov3 = Cov3_wafroc, Var = Var_wafroc)) ``` -------------------------------- ### Example: Convert intrinsic to physical RSM parameters Source: https://dpc10ster.github.io/RJafroc/reference/Util2Physical.html Example usage of Util2Physical. Sets mu, lambda_i, and nu_i, then extracts the physical lambda and nu values. Note that physical values are constrained to be positive and nu must obey 0 <= nu <= 1. ```R mu <- 2;lambda_i <- 20;nu_i <- 1.1512925 lambda <- Util2Physical(mu, lambda_i, nu_i)$lambda nu <- Util2Physical(mu, lambda_i, nu_i)$nu ## note that only the physical values are only constrained to be positive ## the physical variable nu must obey 0 <= nu <= 1 ``` -------------------------------- ### R: kableExtra table with caption Source: https://dpc10ster.github.io/RJafrocFrocBook/index.html Example of creating a table with kableExtra, using collapse_rows and kable_styling options, with a specific caption. ```R kbl(x12, caption = "Summary of optimization results using wAFROC-AUC.", booktabs = TRUE, escape = FALSE) %>% collapse_rows(columns = c(1), valign = "middle") %>% kable_styling(latex_options = c("basic", "scale_down", "HOLD_position"), row_label_position = "c") ``` -------------------------------- ### R output: doBootstrap with seed=2 Source: https://dpc10ster.github.io/RJafrocBook/sources-of-variability.html Shows the output of the same bootstrap example but with `seed=2`. The mean and standard deviation change slightly, illustrating sampling variability. ```R #> Bootstrap variance estimation: #> parametricFOM = TRUE #> seed = 2 #> B = 200 #> OrigAUC = 0.8704519 #> meanAUCboot = 0.8673155 #> stdAUCboot = 0.03815402 ``` -------------------------------- ### Get lesion distribution vector with UtilLesionDistrVector() Source: https://dpc10ster.github.io/RJafrocQuickStart/quick-start-froc.html Calls UtilLesionDistrVector(x) to obtain the lesion distribution vector. The function returns an array with two columns: the first column contains the distinct non-zero lesion counts (14 in this example), and the second column contains the fraction of diseased cases with that number of lesions. The second column sums to unity. ```R lesDistr <- UtilLesionDistrVector(x) lesDistr #> [1] 0.217391304 0.200000000 0.113043478 0.086956522 0.043478261 0.095652174 #> [7] 0.052173913 0.069565217 0.017391304 0.026086957 0.026086957 0.026086957 #> [13] 0.017391304 0.008695652 ``` -------------------------------- ### Example: Convert LROC dataset and compare AUCs Source: https://dpc10ster.github.io/RJafroc/reference/DfLroc2Froc.html Converts datasetCadLroc to FROC, then computes the LROC Wilcoxon AUC and the FROC HrAuc to verify equivalence. ```r frocDataset <- DfLroc2Froc(datasetCadLroc) lrocAuc <- UtilFigureOfMerit(datasetCadLroc, FOM = "Wilcoxon") frocHrAuc <- UtilFigureOfMerit(frocDataset, FOM = "HrAuc") ``` -------------------------------- ### Set parameters for confidence interval example Source: https://dpc10ster.github.io/RJafrocBook/rsm.html Defines the number of samples K=100 and lambda values for two readers. The output prints the parameters. ```R K <- 100 lambdaP <- c(1,2) cat ("K = ", K, ", lambdaP 1st reader = ", lambdaP[1], ", lambdaP 2nd reader = ", lambdaP[2],"\n") ``` ```R ## K = 100 , lambdaP 1st reader = 1 , lambdaP 2nd reader = 2 ``` -------------------------------- ### Test RJafroc installation with PlotCbmFit Source: https://dpc10ster.github.io/RJafroc/index.html Run this R code after installing RJafroc to verify the installation. It creates a CBM fit plot and prints it, which should display two ROC plots in the Plots window. ```R cbmPlot <- PlotCbmFit(c(1, 2), c(0.5, 0.5)) print(cbmPlot) ``` -------------------------------- ### RSM_FPF example call Source: https://dpc10ster.github.io/RJafroc/reference/RSM_FPF.html Example usage of RSM_FPF with a z-vector and lambda=1, showing the computed FPF values. ```r RSM_FPF(c(-Inf,0.1,0.2,0.3),1) #> [1] 0.6321206 0.3688250 0.3434394 0.3175654 ``` -------------------------------- ### RSM_TPF example usage Source: https://dpc10ster.github.io/RJafroc/reference/RSM_TPF.html Example call to RSM_TPF with a lesion distribution and a z-vector, showing the resulting TPF values. ```r lesDistr <- c(0.1,0.3,0.6) RSM_TPF(c(-Inf,0.1,0.2,0.3), 1, 1, 0.9, lesDistr) #> [1] 0.9949968 0.9627697 0.9545997 0.9445033 ``` -------------------------------- ### Example: OR method with pilot dataset and with variance components Source: https://dpc10ster.github.io/RJafroc/reference/SsSampleSizeKGivenJ.html Two calls that should give identical results. The first uses a pilot dataset directly; the second uses variance components obtained from UtilORVarComp. Both produce KRRRC = 170 and powerRRRC = 0.8016186. ```r ## the following two should give identical results SsSampleSizeKGivenJ(dataset02, FOM = "Wilcoxon", effectSize = 0.05, J = 6, method = "OR") #> KRRRC powerRRRC #> 1 170 0.8016186 a <- UtilORVarComp(dataset02, FOM = "Wilcoxon")$VarCom KStar <- length(dataset02$ratings$NL[1,1,,1]) SsSampleSizeKGivenJ(dataset = NULL, J = 6, effectSize = 0.05, method = "OR", list(KStar = KStar, VarTR = a["VarTR",1], Cov1 = a["Cov1",1], Cov2 = a["Cov2",1], Cov3 = a["Cov3",1], Var = a["Var",1])) #> KRRRC powerRRRC #> 1 170 0.8016186 ``` -------------------------------- ### Set up lesion distribution parameters Source: https://dpc10ster.github.io/RJafrocBook/rsm.html Defines the number of cases per lesion count (K2) and the lesion counts (Lk), along with success probabilities for two readers. Prints the parameters to verify setup. ```R K2 <- c(97,2,1);Lk <- c(1,2,3);nuP1 <- 0.5;nuP2 <- 0.9; samples1 <- array(dim = c(sum(K2),length(K2))) cat("K2[1] =", K2[1],", K2[2] =", K2[2],", K2[3] =", K2[3], ", nuP1 =", nuP1, ", nuP2 =", nuP2, "\n") ``` ```R ## K2[1] = 97 , K2[2] = 2 , K2[3] = 1 , nuP1 = 0.5 , nuP2 = 0.9 ``` -------------------------------- ### Example: Calculate PROPROC AUC Source: https://dpc10ster.github.io/RJafroc/reference/UtilAucPROPROC.html Example usage of UtilAucPROPROC with c1 = 0.2 and da = 1.5, returning the AUC value 0.8558655. ```r c1 <- .2;da <- 1.5 UtilAucPROPROC(c1,da) #> [1] 0.8558655 ``` -------------------------------- ### Example: Calculate CBM AUC Source: https://dpc10ster.github.io/RJafroc/reference/UtilAucCBM.html Example usage of UtilAucCBM with mu = 2 and alpha = 0.8, returning the AUC value 0.8370803. ```R mu <- 2;alpha <- 0.8 UtilAucCBM(mu,alpha) #> [1] 0.8370803 ``` -------------------------------- ### RSM_LLF example call Source: https://dpc10ster.github.io/RJafroc/reference/RSM_LLF.html Example call to RSM_LLF with z = c(1,2), mu = 1, nu = 0.5, and the resulting output. ```r RSM_LLF(c(1,2),1,0.5) #> [1] 0.25000000 0.07932763 ``` -------------------------------- ### Example 4: Compute power using OR variance components from dataset Source: https://dpc10ster.github.io/RJafroc/reference/SsPowerGivenJK.html Computes JStar and KStar from dataset02, obtains OR variance components via UtilORVarComp, and calls SsPowerGivenJK with a NULL dataset. The variance components are passed as a list with named elements VarTR, Cov1, Cov2, Cov3, and Var. ```R JStar <- length(dataset02$ratings$NL[1,,1,1]) KStar <- length(dataset02$ratings$NL[1,1,,1]) vcOR <- UtilORVarComp(dataset02, FOM = "Wilcoxon")$VarCom res <- SsPowerGivenJK(dataset = NULL, FOM = "Wilcoxon", effectSize = 0.05, J = 6, K = 251, list(JStar = JStar, KStar = KStar, VarTR = vcOR["VarTR","Estimates"], # replace rhs with actual values as in 4A Cov1 = vcOR["Cov1","Estimates"], # do: Cov2 = vcOR["Cov2","Estimates"], # do: Cov3 = vcOR["Cov3","Estimates"], # do: Var = vcOR["Var","Estimates"])) ``` -------------------------------- ### Example: Simulate an LROC dataset using RSM Source: https://dpc10ster.github.io/RJafroc/reference/SimulateLrocDataset.html Sets a seed, defines parameters, simulates an FROC dataset, and converts it to an LROC dataset using DfFroc2Lroc. ```r set.seed(1) K1 <- 5; K2 <- 5; mu <- 2; lambda <- 1; lesionVector <- rep(1, 5); nu <- 0.8; zeta1 <- -3 frocData <- SimulateFrocDataset(mu, lambda, nu, zeta1, I = 2, J = 5, K1, K2, lesionVector) lrocData <- DfFroc2Lroc(frocData) ``` -------------------------------- ### Run doCalSimulator() with parametric AUC and print results Source: https://dpc10ster.github.io/RJafrocBook/sources-of-variability.html Sets up a ROC counts table and calls doCalSimulator() with parametricFOM=TRUE, seed=1, and P=2000. The returned mu, sigma, zetas, meanAUC, and stdAUC are stored in variables. ```R parametricFOM <- TRUE seed <- 1 set.seed(seed) P <- 2000 RocCountsTable = array(dim = c(2,5)) RocCountsTable[1,] <- c(30,19,8,2,1) RocCountsTable[2,] <- c(5,6,5,12,22) ret <- doCalSimulator(P, parametricFOM, RocCountsTable) mu <- ret$mu sigma <- ret$sigma zetas <- ret$zetas meanAUC_1_2000 <- ret$meanAUC stdAUC_1_2000 <- ret$stdAUC ```