From cadd0b2bf8dee05f57d4421b1a37fb69e6ef0deb Mon Sep 17 00:00:00 2001 From: vcadavez Date: Sat, 17 Feb 2024 10:43:03 +0000 Subject: [PATCH] shiny integration in qraLm --- DESCRIPTION | 2 +- NAMESPACE | 4 + R/Lot2LotGen.R | 1 + R/LotGen.R | 16 +- R/caPartitioningCC.R | 37 +- R/plotLotsECDF.qraLm.R | 38 +- R/runExample.R | 22 + R/summaryLot.qraLm.R | 92 +-- R/summaryRisk.qraLm.R | 74 ++ README.Rmd | 3 +- docs/pkgdown.yml | 2 +- docs/reference/Lot2LotGen.html | 4 + docs/reference/LotGen.html | 37 +- docs/reference/caPartitioningCC.html | 64 +- docs/reference/index.html | 21 + docs/reference/plotLotsECDF.qraLm.html | 44 +- docs/reference/plotRisk.qraLm.html | 2 +- docs/reference/runExample.html | 97 +++ docs/reference/summaryLot.qraLm.html | 24 +- docs/reference/summaryRisk.qraLm.html | 120 +++ docs/reference/summaryServings.qraLm.html | 4 +- docs/reference/summaryUnits.qraLm.html | 4 +- docs/search.json | 2 +- docs/sitemap.xml | 6 + inst/shiny-examples/qraLmShiny/LICENSE | 21 + inst/shiny-examples/qraLmShiny/README.Rmd | 218 ++++++ inst/shiny-examples/qraLmShiny/README.html | 712 ++++++++++++++++++ inst/shiny-examples/qraLmShiny/README.md | 332 ++++++++ inst/shiny-examples/qraLmShiny/app.R | 96 +++ inst/shiny-examples/qraLmShiny/data/data.R | 13 + .../qraLmShiny/data/sampledata.csv | 0 .../qraLmShiny/data/sysdata.rda | Bin 0 -> 322143 bytes .../qraLmShiny/modules/LotGenModule.R | 39 + .../qraLmShiny/modules/barplotModule.R | 33 + .../qraLmShiny/modules/betaDataModule.R | 23 + .../qraLmShiny/modules/betaDistModule.R | 30 + .../qraLmShiny/modules/boxplotModule.R | 32 + .../qraLmShiny/modules/countsLotsDistModule.R | 36 + .../modules/countsUnitsDistModule.R | 37 + .../qraLmShiny/modules/dataModule.R | 26 + .../qraLmShiny/modules/ecdfLotsModule.R | 49 ++ .../qraLmShiny/modules/histModule.R | 44 ++ .../qraLmShiny/modules/logCountsDistModule.R | 45 ++ .../qraLmShiny/modules/mcstatsLotsModule.R | 85 +++ .../qraLmShiny/modules/mcstatsUnitsModule.R | 60 ++ .../qraLmShiny/modules/module_fullscreen.R | 71 ++ .../qraLmShiny/modules/prevLotsModule.R | 19 + .../qraLmShiny/modules/prevUnitsModule.R | 21 + .../qraLmShiny/modules/prevWithinlotsModule.R | 30 + .../qraLmShiny/modules/riskDistModule.R | 63 ++ .../qraLmShiny/modules/riskStatsModule.R | 53 ++ .../qraLmShiny/modules/utility_functions.R | 4 + inst/shiny-examples/qraLmShiny/pages/about.R | 74 ++ .../qraLmShiny/pages/frozenvegetables.R | 20 + .../pages/frozenvegetables/sidebar.R | 24 + .../frozenvegetables/sidebar/stageInputs.R | 83 ++ .../frozenvegetables/sidebar/stageSelector.R | 23 + .../pages/frozenvegetables/stages.R | 52 ++ .../pages/frozenvegetables/stages/Blanching.R | 66 ++ .../pages/frozenvegetables/stages/Cooking.R | 73 ++ .../frozenvegetables/stages/Defrosting.R | 69 ++ .../frozenvegetables/stages/Partitioning.R | 75 ++ .../frozenvegetables/stages/Portioning.R | 67 ++ .../frozenvegetables/stages/Production.R | 89 +++ .../pages/frozenvegetables/stages/Risk.R | 184 +++++ .../pages/frozenvegetables/stages/Testing.R | 82 ++ .../qraLmShiny/pages/rtecantaloupe.R | 22 + .../qraLmShiny/pages/rtecantaloupe/sidebar.R | 24 + .../pages/rtecantaloupe/sidebar/stageInputs.R | 114 +++ .../rtecantaloupe/sidebar/stageSelector.R | 23 + .../qraLmShiny/pages/rtecantaloupe/stages.R | 52 ++ .../pages/rtecantaloupe/stages/Brushing.R | 59 ++ .../rtecantaloupe/stages/ConsumersTransport.R | 76 ++ .../pages/rtecantaloupe/stages/Dicing.R | 67 ++ .../pages/rtecantaloupe/stages/Harvest.R | 65 ++ .../pages/rtecantaloupe/stages/Partitioning.R | 74 ++ .../pages/rtecantaloupe/stages/Production.R | 129 ++++ .../pages/rtecantaloupe/stages/RTEStorage.R | 73 ++ .../pages/rtecantaloupe/stages/Risk.R | 184 +++++ .../pages/rtecantaloupe/stages/StoredDices.R | 79 ++ .../pages/rtecantaloupe/stages/Storing.R | 68 ++ .../pages/rtecantaloupe/stages/Testing.R | 87 +++ .../pages/rtecantaloupe/stages/Transport.R | 85 +++ .../pages/rtecantaloupe/stages/Washing.R | 79 ++ .../qraLmShiny/pages/smokedfish.R | 23 + .../qraLmShiny/pages/smokedfish/sidebar.R | 24 + .../pages/smokedfish/sidebar/stageInputs.R | 115 +++ .../pages/smokedfish/sidebar/stageSelector.R | 23 + .../qraLmShiny/pages/smokedfish/stages.R | 52 ++ .../smokedfish/stages/BriningOrSalting.R | 95 +++ .../pages/smokedfish/stages/Characteristics.R | 117 +++ .../pages/smokedfish/stages/ColdChain.R | 148 ++++ .../pages/smokedfish/stages/Filleting.R | 66 ++ .../pages/smokedfish/stages/Holding.R | 81 ++ .../qraLmShiny/pages/smokedfish/stages/Home.R | 120 +++ .../pages/smokedfish/stages/Packaging.R | 60 ++ .../pages/smokedfish/stages/Portioning.R | 66 ++ .../pages/smokedfish/stages/Prefilleting.R | 79 ++ .../pages/smokedfish/stages/Production.R | 101 +++ .../qraLmShiny/pages/smokedfish/stages/Risk.R | 183 +++++ .../pages/smokedfish/stages/Slicing.R | 69 ++ .../pages/smokedfish/stages/Smoking.R | 72 ++ .../smokedfish/stages/rteCharacteristics.R | 149 ++++ inst/shiny-examples/qraLmShiny/pages/user.R | 18 + inst/shiny-examples/qraLmShiny/www/custom.css | 75 ++ .../qraLmShiny/www/img/favicon.ico | Bin 0 -> 87194 bytes .../qraLmShiny/www/img/linkedin_icon.png | Bin 0 -> 5823 bytes .../qraLmShiny/www/img/logo.png | Bin 0 -> 22632 bytes .../qraLmShiny/www/img/logo.svg | 1 + .../qraLmShiny/www/img/logo_small.png | Bin 0 -> 56497 bytes man/Lot2LotGen.Rd | 2 + man/LotGen.Rd | 17 +- man/caPartitioningCC.Rd | 38 +- man/plotLotsECDF.qraLm.Rd | 38 +- man/runExample.Rd | 18 + man/summaryLot.qraLm.Rd | 20 +- man/summaryRisk.qraLm.Rd | 39 + pkgdown/_pkgdown.yml | 9 +- 118 files changed, 6966 insertions(+), 205 deletions(-) create mode 100644 R/runExample.R create mode 100644 R/summaryRisk.qraLm.R create mode 100644 docs/reference/runExample.html create mode 100644 docs/reference/summaryRisk.qraLm.html create mode 100644 inst/shiny-examples/qraLmShiny/LICENSE create mode 100644 inst/shiny-examples/qraLmShiny/README.Rmd create mode 100644 inst/shiny-examples/qraLmShiny/README.html create mode 100644 inst/shiny-examples/qraLmShiny/README.md create mode 100644 inst/shiny-examples/qraLmShiny/app.R create mode 100644 inst/shiny-examples/qraLmShiny/data/data.R create mode 100644 inst/shiny-examples/qraLmShiny/data/sampledata.csv create mode 100644 inst/shiny-examples/qraLmShiny/data/sysdata.rda create mode 100644 inst/shiny-examples/qraLmShiny/modules/LotGenModule.R create mode 100644 inst/shiny-examples/qraLmShiny/modules/barplotModule.R create mode 100644 inst/shiny-examples/qraLmShiny/modules/betaDataModule.R create mode 100644 inst/shiny-examples/qraLmShiny/modules/betaDistModule.R create mode 100644 inst/shiny-examples/qraLmShiny/modules/boxplotModule.R create mode 100644 inst/shiny-examples/qraLmShiny/modules/countsLotsDistModule.R create mode 100644 inst/shiny-examples/qraLmShiny/modules/countsUnitsDistModule.R create mode 100644 inst/shiny-examples/qraLmShiny/modules/dataModule.R create mode 100644 inst/shiny-examples/qraLmShiny/modules/ecdfLotsModule.R create mode 100644 inst/shiny-examples/qraLmShiny/modules/histModule.R create mode 100644 inst/shiny-examples/qraLmShiny/modules/logCountsDistModule.R create mode 100644 inst/shiny-examples/qraLmShiny/modules/mcstatsLotsModule.R create mode 100644 inst/shiny-examples/qraLmShiny/modules/mcstatsUnitsModule.R create mode 100644 inst/shiny-examples/qraLmShiny/modules/module_fullscreen.R create mode 100644 inst/shiny-examples/qraLmShiny/modules/prevLotsModule.R create mode 100644 inst/shiny-examples/qraLmShiny/modules/prevUnitsModule.R create mode 100644 inst/shiny-examples/qraLmShiny/modules/prevWithinlotsModule.R create mode 100644 inst/shiny-examples/qraLmShiny/modules/riskDistModule.R create mode 100644 inst/shiny-examples/qraLmShiny/modules/riskStatsModule.R create mode 100644 inst/shiny-examples/qraLmShiny/modules/utility_functions.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/about.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/frozenvegetables.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/frozenvegetables/sidebar.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/frozenvegetables/sidebar/stageInputs.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/frozenvegetables/sidebar/stageSelector.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/frozenvegetables/stages.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/frozenvegetables/stages/Blanching.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/frozenvegetables/stages/Cooking.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/frozenvegetables/stages/Defrosting.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/frozenvegetables/stages/Partitioning.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/frozenvegetables/stages/Portioning.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/frozenvegetables/stages/Production.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/frozenvegetables/stages/Risk.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/frozenvegetables/stages/Testing.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/rtecantaloupe.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/rtecantaloupe/sidebar.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/rtecantaloupe/sidebar/stageInputs.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/rtecantaloupe/sidebar/stageSelector.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/rtecantaloupe/stages.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/rtecantaloupe/stages/Brushing.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/rtecantaloupe/stages/ConsumersTransport.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/rtecantaloupe/stages/Dicing.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/rtecantaloupe/stages/Harvest.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/rtecantaloupe/stages/Partitioning.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/rtecantaloupe/stages/Production.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/rtecantaloupe/stages/RTEStorage.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/rtecantaloupe/stages/Risk.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/rtecantaloupe/stages/StoredDices.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/rtecantaloupe/stages/Storing.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/rtecantaloupe/stages/Testing.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/rtecantaloupe/stages/Transport.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/rtecantaloupe/stages/Washing.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/smokedfish.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/smokedfish/sidebar.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/smokedfish/sidebar/stageInputs.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/smokedfish/sidebar/stageSelector.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/smokedfish/stages.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/smokedfish/stages/BriningOrSalting.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/smokedfish/stages/Characteristics.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/smokedfish/stages/ColdChain.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/smokedfish/stages/Filleting.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/smokedfish/stages/Holding.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/smokedfish/stages/Home.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/smokedfish/stages/Packaging.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/smokedfish/stages/Portioning.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/smokedfish/stages/Prefilleting.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/smokedfish/stages/Production.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/smokedfish/stages/Risk.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/smokedfish/stages/Slicing.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/smokedfish/stages/Smoking.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/smokedfish/stages/rteCharacteristics.R create mode 100644 inst/shiny-examples/qraLmShiny/pages/user.R create mode 100644 inst/shiny-examples/qraLmShiny/www/custom.css create mode 100644 inst/shiny-examples/qraLmShiny/www/img/favicon.ico create mode 100644 inst/shiny-examples/qraLmShiny/www/img/linkedin_icon.png create mode 100644 inst/shiny-examples/qraLmShiny/www/img/logo.png create mode 100644 inst/shiny-examples/qraLmShiny/www/img/logo.svg create mode 100644 inst/shiny-examples/qraLmShiny/www/img/logo_small.png create mode 100644 man/runExample.Rd create mode 100644 man/summaryRisk.qraLm.Rd diff --git a/DESCRIPTION b/DESCRIPTION index ef3aaee..655e0eb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -17,7 +17,7 @@ Description: qraLm: A R package for quantitative risk assessment for Listeria mo URL: https://github.com/vcadavez/qraLm BugReports: https://github.com/vcadavez/qraLm/issues Depends: R (>= 3.5.0) -Imports: Rdpack, Hmisc, extraDistr, mc2d, matrixStats, DT, dplyr, +Imports: Rdpack, Hmisc, extraDistr, mc2d, matrixStats, DT, dplyr, shiny, ggplot2, plotly, Rcpp, odeintr, doseresponsemodels LinkingTo: Rcpp, odeintr, BH RdMacros: Rdpack diff --git a/NAMESPACE b/NAMESPACE index 430ff6c..d19fbc9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -32,6 +32,7 @@ export(fvTesting) export(plotLotsECDF.qraLm) export(plotRisk.qraLm) export(printMC.qraLm) +export(runExample) export(sfBrineORsaltCC) export(sfBriningCC) export(sfCharacteristics) @@ -48,6 +49,7 @@ export(sfSmearingCC) export(sfSmoking) export(sfTesting) export(summaryLot.qraLm) +export(summaryRisk.qraLm) export(summaryServings.qraLm) export(summaryUnits.qraLm) importFrom(DT,datatable) @@ -62,7 +64,9 @@ importFrom(dplyr,"%>%") importFrom(extraDistr,dbbinom) importFrom(extraDistr,rtbinom) importFrom(extraDistr,rtnorm) +importFrom(matrixStats,rowMeans2) importFrom(matrixStats,rowSums2) +importFrom(matrixStats,rowWeightedMeans) importFrom(mc2d,rdirichlet) importFrom(mc2d,rmultinomial) importFrom(mc2d,rpert) diff --git a/R/Lot2LotGen.R b/R/Lot2LotGen.R index 0e670c8..f3c8e10 100644 --- a/R/Lot2LotGen.R +++ b/R/Lot2LotGen.R @@ -21,6 +21,7 @@ #' @param propVarInter proportion of the total variance (\eqn{C0\_sdLog10^2}) attributed #' to between-lot variance. The remaining (`1-propVarInter`) is the proportion of within-lot variance. #' @param Poisson need to be defined +#' @param ... Other options used to control [LotGen()] #' #' @return A list of four elements: #' \describe{ diff --git a/R/LotGen.R b/R/LotGen.R index 929ea98..dbcf1f6 100644 --- a/R/LotGen.R +++ b/R/LotGen.R @@ -1,17 +1,23 @@ #' @title Generation of contaminated lots #' #' @description -#' The function [LotGen()] generates a matrix of contaminated lots from information on the parameters of a normal distribution (mean, sd) +#' The function [LotGen()] generates a matrix of contaminated lots from information on the +#' parameters of a normal distribution (mean, sd) #' representing the microbial concentration in the contaminated units (log10 CFU/g). -#' Every row of the matrix corresponds to a production lot, broken down in units or portions, which are the columns of the matrix. -#' There is no assumption that lots can have different prevalence values, and therefore the microbial numbers of all units or portions produced in a lot +#' Every row of the matrix corresponds to a production lot, broken down in units or portions, +#' which are the columns of the matrix. +#' There is no assumption that lots can have different prevalence values, and therefore the +#' microbial numbers of all units or portions produced in a lot #' are sampled from a microbial concentration distribution. #' @param nLots number of lots sampled or size of the Monte Carlo simulation (scalar). #' @param sizeLot number of units or portions produced in a lot (scalar). #' @param unitSize (`g`) weight of single unit or portion from a lot (scalar). #' @param P prevalence of contaminated lots (scalar) -#' @param C0MeanLog (log10 CFU/g) mean parameter of the normal distribution representing the variability in the microbial concentration of contaminated units (scalar or vector). -#' @param C0SdLog (log10 CFU/g) standard deviation parameter of the normal distribution representing the variability in the microbial concentration of contaminated units (scalar or vector). +#' @param C0MeanLog (log10 CFU/g) mean parameter of the normal distribution representing +#' the variability in the microbial concentration of contaminated units (scalar or vector). +#' @param C0SdLog (log10 CFU/g) standard deviation parameter of the normal distribution +#' representing the variability in the microbial concentration of contaminated units (scalar or vector). +#' @param ... Other options used to control [LotGen()] #' @return A list of two elements: #' \describe{ #' \item{N}{(`CFU`) A matrix of size `nLots` lots by `sizeLot` units representing the microbial numbers in the units or portions from contaminated lots;} diff --git a/R/caPartitioningCC.R b/R/caPartitioningCC.R index ff177a8..f51a4a0 100644 --- a/R/caPartitioningCC.R +++ b/R/caPartitioningCC.R @@ -1,41 +1,51 @@ #' @title Cross-contamination of cantaloupe during dicing and partitioning into packed units #' #' @description -#' The [caPartitioningCC()] function simulates the potential cross-contamination of cantaloupes, when in direct contact with the dicing machine +#' The [caPartitioningCC()] function simulates the potential cross-contamination of cantaloupes, +#' when in direct contact with the dicing machine #' or knives, followed by the partitioning of all dices produced in one processing lot (sublot) into packed units. #' The cross-contamination algorithm accounts for four possible scenarios: #' \enumerate{ #' \item cross-contamination occurring in sublots already contaminated; #' \item contamination occurring in sublots that were not contaminated; #' \item no cross-contamination occurring in sublots already contaminated; and -#' \item no cross-contamination occurring in sublots that were not contaminated. Probabilities of occurrence of every event are computed. +#' \item no cross-contamination occurring in sublots that were not contaminated. Probabilities +#' of occurrence of every event are computed. #' } -#' The partitioning algorithm randomly distributes the total numbers of cells from a contaminated sublot of dices into packed units. The dispersion factor `b`, -#' which is a parameter of the beta distribution, indicates the extent of cell clustering in the bulk of dices in the sublot, and ultimately +#' The partitioning algorithm randomly distributes the total numbers of cells from a contaminated sublot +#' of dices into packed units. The dispersion factor `b`, +#' which is a parameter of the beta distribution, indicates the extent of cell clustering in the bulk +#' of dices in the sublot, and ultimately #' the heterogeneity in the number of cells distributed among pack units. #' #' @param data a list of: #' \describe{ -#' \item{`N`}{(`CFU`) A matrix of size `newMC` sublots by `sizeSublot` portions of dices from one cantaloupe representing the numbers of \emph{L. monocytogenes} -#' in dices;} +#' \item{`N`}{(`CFU`) A matrix of size `newMC` sublots by `sizeSublot` portions of dices from one +#' cantaloupe representing the numbers of \emph{L. monocytogenes} in dices;} #' \item{`P`}{Prevalence of contaminated sublots (scalar).} #' } #' @param probCCDice Probability of cross-contamination from the dicing machine (scalar). -#' @param trDicerMean Mean of the transfer coefficient of \emph{L. monocytogenes} from dicing machine to cantaloupe flesh (scalar or vector). -#' @param trDicerSd Standard deviation of the transfer coefficient of \emph{L. monocytogenes} from dicing machine to cantaloupe +#' @param trDicerMean Mean of the transfer coefficient of \emph{L. monocytogenes} from dicing +#' machine to cantaloupe flesh (scalar or vector). +#' @param trDicerSd Standard deviation of the transfer coefficient of \emph{L. monocytogenes} +#' from dicing machine to cantaloupe #' flesh (scalar or vector). -#' @param nDicer (`CFU`) Numbers of \emph{L. monocytogenes} on the surface of the dicing machine ready to be transferred (scalar or vector). +#' @param nDicer (`CFU`) Numbers of \emph{L. monocytogenes} on the surface of the dicing machine +#' ready to be transferred (scalar or vector). # #' @param newMC Number of sublots (scalar). +#' @param nLots See [Lot2LotGen()]. #' @param sizeLot Number of cantaloupes from a harvested lot (scalar). #' @param sizeSublot Number of cantaloupes processed in a sublot. It should be a multiple of `sizeLot` (scalar). #' @param cantaWeight (`g`) weight of a cantaloupe #' @param pulpYield (`%`) Cantaloupe pulp yield (scalar or vector). #' @param unitSize (`g`) Weight of a pack of cantaloupe dices (scalar). -#' @param b Dispersion factor of the beta distribution representing the degree of heterogeneity in the number of cells between pack units (scalar). +#' @param b Dispersion factor of the beta distribution representing the degree of heterogeneity in the number +#' of cells between pack units (scalar). #' #' @return A list with four elements: #' \describe{ -#' \item{`N`}{(`CFU`) A matrix of size `newMC` sublots by Number_packs number of packs containing the numbers of \emph{L. monocytogenes} in a pack, +#' \item{`N`}{(`CFU`) A matrix of size `newMC` sublots by Number_packs number of packs containing +#' the numbers of \emph{L. monocytogenes} in a pack, #' from contaminated lots;} #' \item{`P`}{Prevalence of contaminated sublots (scalar);} #' \item{`sizeSublot`}{Number of cantaloupes processed in a sublot (scalar);} @@ -63,8 +73,9 @@ #' @export #' #' @note The value of \eqn{beta = 1} represents moderate clustering of cells in the bulk of diced cantaloupe from a -#' sublot \insertCite{Nauta2005;textual}{qraLm}. \insertCite{Hoelzer2012;textual}{qraLm} established the log 10 of the transfer coefficient -#' of \emph{L. monocytogenes} from knives to vegetables as a normal distribution with \eqn{TRdicer\_mean = -1.42} and \eqn{TRdicer\_sd = 0.52}. +#' sublot \insertCite{Nauta2005;textual}{qraLm}. \insertCite{Hoelzer2012;textual}{qraLm} established the log 10 of +#' the transfer coefficient of \emph{L. monocytogenes} from knives to vegetables as a normal distribution with +#' \eqn{TRdicer\_mean = -1.42} and \eqn{TRdicer\_sd = 0.52}. #' #' @examples #' library(extraDistr) diff --git a/R/plotLotsECDF.qraLm.R b/R/plotLotsECDF.qraLm.R index 3dfc8b5..487c549 100644 --- a/R/plotLotsECDF.qraLm.R +++ b/R/plotLotsECDF.qraLm.R @@ -2,7 +2,7 @@ #' #' @title plotLotsECDF Generic plot function to plot the ECDF #' @param x qraLm object see [Lot2LotGen()] -#' @param ... optional plot parameters passed to the plot function +#' @param ... Optional plot parameters passed to the [plotLotsECDF()] function #' @author Vasco Cadavez #' #' @importFrom stats weighted.mean @@ -12,25 +12,25 @@ #' @examples #' #' prod <- Lot2LotGen( -#' nLots = 1000, -#' sizeLot = 1000, -#' unitSize = 500, -#' betaAlpha = 0.5112, -#' betaBeta = 9.959, -#' C0MeanLog = 1.023, -#' C0SdLog = 0.3267, -#' propVarInter = 0.7 -#' ) +#' nLots = 1000, +#' sizeLot = 1000, +#' unitSize = 500, +#' betaAlpha = 0.5112, +#' betaBeta = 9.959, +#' C0MeanLog = 1.023, +#' C0SdLog = 0.3267, +#' propVarInter = 0.7 +#' ) #' prod1 <- Lot2LotGen( -#' nLots = 1000, -#' sizeLot = 1000, -#' unitSize = 500, -#' betaAlpha = 0.9112, -#' betaBeta = 2.959, -#' C0MeanLog = 2.023, -#' C0SdLog = 0.5267, -#' propVarInter = 0.7 -#' ) +#' nLots = 1000, +#' sizeLot = 1000, +#' unitSize = 500, +#' betaAlpha = 0.9112, +#' betaBeta = 2.959, +#' C0MeanLog = 2.023, +#' C0SdLog = 0.5267, +#' propVarInter = 0.7 +#' ) #' #' plotLotsECDF.qraLm(prod1) #' diff --git a/R/runExample.R b/R/runExample.R new file mode 100644 index 0000000..8bd4465 --- /dev/null +++ b/R/runExample.R @@ -0,0 +1,22 @@ +#' @title Shiny application for `qraLm` package +#' +#' @description +#' Shiny application to simulate quantitative risk assessment for *L. monocytogenes* +#' in Frozen Vegetables, Diced RTE Cantaloupe and Cold-smoked RTE Fish. +#' +#' @author Vasco Cadavez \email{vcadavez@ipb.pt} +#' +#' @references +#' \insertRef{stats}{qraLm} +#' +#' @importFrom Rdpack reprompt +#' +#' @export +runExample <- function() { + appDir <- system.file("shiny-examples", "qraLmShiny", package = "qraLm") + if (appDir == "") { + stop("Could not find example directory. Try re-installing `qraLm`.", call. = FALSE) + } + + shiny::runApp(appDir, display.mode = "normal") +} \ No newline at end of file diff --git a/R/summaryLot.qraLm.R b/R/summaryLot.qraLm.R index 68f2095..b467953 100644 --- a/R/summaryLot.qraLm.R +++ b/R/summaryLot.qraLm.R @@ -1,4 +1,4 @@ -#' Print summary MC results +#' Print summary MC results at Lot level #' #' @title summaryLot Generic print function to print the between lots MC summary statistics #' @param x qraLm object. See [Lot2LotGen()] @@ -12,15 +12,15 @@ #' #' @examples #' prod <- Lot2LotGen( -#' nLots = 1000, -#' sizeLot = 1000, -#' unitSize = 500, -#' betaAlpha = 0.5112, -#' betaBeta = 9.959, -#' C0MeanLog = 1.023, -#' C0SdLog = 0.3267, -#' propVarInter = 0.7, -#' Poisson = FALSE +#' nLots = 1000, +#' sizeLot = 1000, +#' unitSize = 500, +#' betaAlpha = 0.5112, +#' betaBeta = 9.959, +#' C0MeanLog = 1.023, +#' C0SdLog = 0.3267, +#' propVarInter = 0.7, +#' Poisson = FALSE #' ) #' #' summaryLot.qraLm(prod) @@ -33,62 +33,64 @@ summaryLot.qraLm <- function(x, ...) { if (exists("unitSize", x) == TRUE) { lotN <- rowMeans(x$N / x$unitSize, na.rm = TRUE) } else { - lotN <- rowMeans(x$N, na.rm = TRUE) + lotN <- rowMeans(x$N, na.rm = TRUE) } if (exists("ProbUnitPos", x) == TRUE) { - NStats <- Hmisc::wtd.quantile(lotN, - weights = x$ProbUnitPos, - probs = c(0.0, 0.5, 0.025, 0.975, 1.0), - normwt = TRUE, na.rm = TRUE - ) - NStatsMean <- stats::weighted.mean(lotN, w = x$ProbUnitPos, na.rm = TRUE) + NStats <- Hmisc::wtd.quantile(lotN, + weights = x$ProbUnitPos, + probs = c(0.0, 0.5, 0.025, 0.975, 1.0), + normwt = TRUE, na.rm = TRUE) + + NStatsMean <- stats::weighted.mean(lotN, w = x$ProbUnitPos, na.rm = TRUE) } else { NStats <- Hmisc::wtd.quantile(lotN, - weights = rep(1, nrow(x$N)), - probs = c(0.00, 0.0, 0.025, 0.975, 1.00), - normwt = TRUE, na.rm = TRUE - ) + weights = rep(1, nrow(x$N)), + probs = c(0.00, 0.0, 0.025, 0.975, 1.00), + normwt = TRUE, na.rm = TRUE) + NStatsMean <- mean(lotN, na.rm = TRUE) } - NStatsMin <- NStats[1] + NStatsMin <- NStats[1] NStatsMedian <- NStats[2] - Q2.5 <- NStats[3] - Q97.5 <- NStats[4] - NStatsMax <- NStats[5] + Q2.5 <- NStats[3] + Q97.5 <- NStats[4] + NStatsMax <- NStats[5] + Counts <- rbind( - unname(NStatsMin), - unname(Q2.5), - unname(NStatsMean), - unname(NStatsMedian), - unname(Q97.5), - unname(NStatsMax) - ) - # log10Counts <- round(log10(ceiling(Counts)), digits=4) - log10Counts <- round(log10(Counts), digits = 4) + unname(NStatsMin), + unname(Q2.5), + unname(NStatsMean), + unname(NStatsMedian), + unname(Q97.5), + unname(NStatsMax) + ) + # logs function + log_var <- function(x) { + ifelse(x != 0, log10(x), 0) + } + + log10Counts <- round(log_var(Counts), digits = 6) Statistics <- c("Minimum", "pct 2.5th", "Mean", "Median", "pct 97.5th", "Maximum") MCstats <- data.frame(Statistics, Counts, log10Counts) - if (exists("ProbUnitPos", x) == TRUE) { names(MCstats) <- c("Statistics", "CFU/g", "log10 CFU/g") DT::datatable(MCstats, - caption = "Summary statistics: between lots mean counts", - class = "display", - fillContainer = FALSE, - options = list(dom = "t") - ) |> + caption = "Summary statistics: between lots mean counts", + class = "display", + fillContainer = FALSE, + options = list(dom = "t")) |> DT::formatSignif(columns = c("CFU/g", "log10 CFU/g"), digits = 4) } else { names(MCstats) <- c("Statistics", "CFU/Melon", "log10 CFU/Melon") DT::datatable(MCstats, - caption = "Summary statistics: between lots mean counts", - class = "display", - fillContainer = FALSE, - options = list(dom = "t") - ) |> + caption = "Summary statistics: between lots mean counts", + class = "display", + fillContainer = FALSE, + options = list(dom = "t")) |> DT::formatSignif(columns = c("CFU/Melon", "log10 CFU/Melon"), digits = 4) } } diff --git a/R/summaryRisk.qraLm.R b/R/summaryRisk.qraLm.R new file mode 100644 index 0000000..b4886ad --- /dev/null +++ b/R/summaryRisk.qraLm.R @@ -0,0 +1,74 @@ +#' Print summary MC risk results +#' +#' @title summaryRisk generic function to print the risk summary statistics +#' @param x qraLm object. See [Lot2LotGen()] +#' @param ... optional plot parameters passed to the plot function +#' @author Vasco Cadavez +#' +#' @importFrom stats weighted.mean +#' @importFrom Hmisc wtd.quantile +#' @importFrom DT datatable +#' @importFrom DT formatSignif +#' @importFrom matrixStats rowMeans2 rowWeightedMeans +#' +#' @examples +#' dat <- Lot2LotGen( +#' nLots = 500, +#' sizeLot = 500, +#' unitSize = 500, +#' betaAlpha = 0.5112, +#' betaBeta = 9.959, +#' C0MeanLog = 1.023, +#' C0SdLog = 0.3267, +#' propVarInter = 0.7 +#' ) +#' DRmodel = "JEMRA" +#' population = 2 +#' res <- DRForModel(dat, +#' model=DRmodel, +#' population = population) +#' +#' summaryRisk.qraLm(res) +#' +#' @export +#' +summaryRisk.qraLm <- function(x, ...) { + # if (class(x)!= "qraLm") + # stop("object is not of class 'qraLm'") + if (exists("ProbUnitPos", x) == TRUE) { + wRiskLotMean <- matrixStats::rowWeightedMeans(x$Risk, W = x$ProbUnitPos) + } else { + wRiskLotMean <- matrixStats::rowMeans2(x$Risk) + } + + log_risk = function(x){ + ifelse(x!=0, log10(x), 0) + } + + wRiskLotMeanLog <- log_risk(wRiskLotMean) + +riskMin <- min(wRiskLotMeanLog) +riskMax <- max(wRiskLotMeanLog) +riskMedian <- stats::median(wRiskLotMeanLog) +riskMean <- mean(wRiskLotMeanLog, na.rm = TRUE) +riskQ2.5 <- stats::quantile(wRiskLotMeanLog, probs = c(0.025), na.rm = TRUE) + riskQ97.5 <- stats::quantile(wRiskLotMeanLog, probs = c(0.975), na.rm = TRUE) + + risk <- rbind( + unname(riskMin), + unname(riskQ2.5), + unname(riskMean), + unname(riskMedian), + unname(riskQ97.5), + unname(riskMax) + ) + Statistics <- c("Minimum", "pct 2.5th", "Mean", "Median", "pct 97.5th", "Maximum") + Riskstats <- data.frame(Statistics, risk) + names(Riskstats) <- c("Statistics", "log10 Risk") + DT::datatable(Riskstats, + caption = "Summary statistics of Risk per lot", + class = "display", + fillContainer = FALSE, + options = list(dom = "t") ) |> + DT::formatSignif(columns = c("log10 Risk"), digits = 4) +} diff --git a/README.Rmd b/README.Rmd index 2e3d7ab..1e765b2 100644 --- a/README.Rmd +++ b/README.Rmd @@ -17,7 +17,8 @@ knitr::opts_chunk$set( A R package to develop quantitative risk assessment for *L. monocytogenes* in Frozen Vegetables, Diced RTE Cantaloupe and Cold-smoked RTE Fish. -- Version developed scope of the [JEMRA workgroup](https://www.who.int/publications/m/item/jemra-of-listeria-monocytogenes-in-foods). +- Version developed under the scope of the [Joint FAO/WHO](https://www.who.int/publications/m/item/jemra-of-listeria-monocytogenes-in-foods) + Expert meeting on microbiological risk assessment of Listeria monocytogenes in foods. ## Installation diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 2e16e7e..c3f1611 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -2,7 +2,7 @@ pandoc: 3.1.1 pkgdown: 2.0.7 pkgdown_sha: ~ articles: {} -last_built: 2024-02-17T00:24Z +last_built: 2024-02-17T10:41Z urls: reference: https://vcadavez.github.io/qraLm/reference article: https://vcadavez.github.io/qraLm/articles diff --git a/docs/reference/Lot2LotGen.html b/docs/reference/Lot2LotGen.html index 89e9b5e..aa77694 100644 --- a/docs/reference/Lot2LotGen.html +++ b/docs/reference/Lot2LotGen.html @@ -125,6 +125,10 @@

ArgumentsLotGen()

+

Value

diff --git a/docs/reference/LotGen.html b/docs/reference/LotGen.html index 616f392..920166a 100644 --- a/docs/reference/LotGen.html +++ b/docs/reference/LotGen.html @@ -1,12 +1,18 @@ -Generation of contaminated lots — LotGen • qraLmGeneration of contaminated lots — LotGen • qraLmCross-contamination of cantaloupe during dicing and partitioning into packed units — caPartitioningCC • qraLmCross-contamination of cantaloupe during dicing and partitioning into packed units — caPartitioningCC • qraLmShiny application for qraLm package — runExample • qraLm + Skip to contents + + +
+
+
+ +
+

Shiny application to simulate quantitative risk assessment for L. monocytogenes +in Frozen Vegetables, Diced RTE Cantaloupe and Cold-smoked RTE Fish.

+
+ +
+

Usage

+
runExample()
+
+ +
+

References

+

Team RC (2022). +R: A Language and Environment for Statistical Computing. +R Foundation for Statistical Computing, Vienna, Austria. +https://www.R-project.org/.

+
+
+

Author

+

Vasco Cadavez vcadavez@ipb.pt

+
+ +
+ + +
+ + + + + + + diff --git a/docs/reference/summaryLot.qraLm.html b/docs/reference/summaryLot.qraLm.html index 6ccf408..6988301 100644 --- a/docs/reference/summaryLot.qraLm.html +++ b/docs/reference/summaryLot.qraLm.html @@ -1,5 +1,5 @@ -summaryLot Generic print function to print the between lots MC summary statistics — summaryLot.qraLm • qraLmsummaryLot Generic print function to print the between lots MC summary statistics — summaryLot.qraLm • qraLm @@ -52,7 +52,7 @@
-

Print summary MC results

+

Print summary MC results at Lot level

@@ -78,20 +78,20 @@

Author<

Examples

prod <- Lot2LotGen(
-  nLots        = 1000,
-  sizeLot      = 1000,
-  unitSize     = 500,
-  betaAlpha    = 0.5112,
-  betaBeta     = 9.959,
-  C0MeanLog    = 1.023,
-  C0SdLog      = 0.3267,
-  propVarInter = 0.7,
-  Poisson      = FALSE
+                   nLots        = 1000,
+                   sizeLot      = 1000,
+                   unitSize     = 500,
+                   betaAlpha    = 0.5112,
+                   betaBeta     = 9.959,
+                   C0MeanLog    = 1.023,
+                   C0SdLog      = 0.3267,
+                   propVarInter = 0.7,
+                   Poisson      = FALSE
 )
 
 summaryLot.qraLm(prod)
 
- +