Skip to content

Commit

Permalink
add parallelisation to lqas_simulate; fix #73
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestguevarra committed Dec 28, 2024
1 parent ef7ad94 commit bb4a95a
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 75 deletions.
3 changes: 3 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ URL: https://nutriverse.io/sleacr/,https://github.com/nutriverse/sleacr
BugReports: https://github.com/nutriverse/sleacr/issues
Config/testthat/edition: 3
VignetteBuilder: knitr
Imports:
parallel,
parallelly
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ importFrom(graphics,legend)
importFrom(graphics,lines)
importFrom(graphics,plot)
importFrom(graphics,points)
importFrom(parallel,mclapply)
importFrom(parallelly,availableCores)
importFrom(stats,lowess)
importFrom(stats,phyper)
22 changes: 14 additions & 8 deletions R/04-test_classifier.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ lqas_simulate_population <- function(proportion, pop) {
#' Default is 50 runs.
#' @param replicates Number of replicate LQAS simulations to perform.
#' Default is set to 20 replicates.
#' @param cores The number of computer cores to use/number of child processes
#' will be run simultaneously.
#'
#' @returns A data.frame with variable `cases` for total number of
#' covered/cases, `outcome` for LQAS outcome, and `proportion` for the
Expand Down Expand Up @@ -163,19 +165,21 @@ lqas_simulate_runs <- function(pop,
pLower = 0,
pUpper = 1,
fine = 0.01,
runs = 50) {
runs = 50,
cores = parallelly::availableCores(omit = 1)) {
proportion <- rep.int(
seq(from = pLower, to = pUpper, by = fine), times = runs
) |>
sort()

result <- lapply(
result <- parallel::mclapply(
X = proportion,
FUN = lqas_simulate_run,
pop = pop,
n = n,
dLower = dLower,
dUpper = dUpper
dUpper = dUpper,
mc.cores = cores
) |>
(\(x) do.call(rbind, x))()

Expand All @@ -197,20 +201,22 @@ lqas_simulate_test <- function(pop,
pUpper = 1,
fine = 0.01,
runs = 50,
replicates = 20) {
replicates = 20,
cores = parallelly::availableCores(omit = 1)) {
proportion <- rep.int(
seq(from = pLower, to = pUpper, by = fine), times = runs
) |>
sort() |>
rep(times = replicates)

x <- lapply(
x <- parallel::mclapply(
X = proportion,
FUN = lqas_simulate_run,
pop = pop,
n = n,
dLower = dLower,
dUpper = dUpper
dUpper = dUpper,
mc.cores = cores
) |>
(\(x) do.call(rbind, x))()

Expand All @@ -232,7 +238,8 @@ lqas_simulate_test <- function(pop,
#'
#' @param x Simulated results data produced by [lqas_simulate_test()]
#'
#' @returns A list of LQAS misclassification probabilities results
#' @returns A list object of class `lqasClass` for LQAS misclassification
#' probabilities results
#'
#' @examples
#' sim <- lqas_simulate_test(
Expand Down Expand Up @@ -311,7 +318,6 @@ lqas_get_class_prob <- function(x) {
#' @export
#'


print.lqasClass <- function(x, ...) {
cat(" Low : ", round(x$probs[1], 4), "\n",
" Moderate : ", round(x$probs[2], 4), "\n",
Expand Down
25 changes: 19 additions & 6 deletions R/sleacr.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
################################################################################
#

#'
#' Simplified Lot Quality Assurance Sampling Evaluation of Access and Coverage
#' (SLEAC) Tools
#'
#' In the recent past, measurement of coverage has been mainly through two-stage
#' cluster sampled surveys either as part of a nutrition assessment or through a
#' specific coverage survey known as Centric Systematic Area Sampling (CSAS).
#' However, such methods are resource intensive and often only used for final
#' programme evaluation meaning results arrive too late for programme
#' adaptation. SLEAC, which stands for Simplified Lot Quality Assurance Sampling
#' Evaluation of Access and Coverage, is a low resource method designed
#' specifically to address this limitation and is used regularly for monitoring,
#' planning and importantly, timely improvement to programme quality, both for
#' agency and Ministry of Health (MoH) led programmes. This package provides
#' functions for use in conducting a SLEAC assessment.
#'
#' @references
#' Myatt, Mark et al. 2012. Semi-Quantitative Evaluation of Access and
#' Coverage (SQUEAC)/Simplified Lot Quality Assurance Sampling Evaluation of
#' Access and Coverage (SLEAC) Technical Reference. Washington, DC: FHI 360/FANTA.
#'
#' @keywords internal
#'
#' @docType package
#' @name sleacr
#' @importFrom graphics abline legend lines plot points
#' @importFrom stats lowess phyper
#' @importFrom parallel mclapply
#' @importFrom parallelly availableCores
#'
#'
#
################################################################################
"_PACKAGE"


112 changes: 58 additions & 54 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
@@ -1,104 +1,108 @@
Badjia
Bagbe
Bagbo
Baimba
Bainyawa
Bambawo
Bandajuma
Bangema
Baoma
Benduma
Bevehun
Bongor
Bowohun
Bumpe
Bumuvulahun
CMAM
CMD
CSAS
CodeFactor
Codecov
Damia
Dar
Deilenga
Dukpuibu
FANTA
FHI
Failor
Feiba
Foya
Fuinda
Gandorhun
Gbanahun
Gbangaima
Gbanja
Gbo
Gbongboma
Gboyeiya
Geihun
Gondama
Hotawuloma
Jagbewema
Gorapon
Huawuma
Jaiama
Jaluahun
Jimmi
Jojohun
Jolu
Kaimbe
Jongo
Juhun
Kaduawo
Kakua
Kangama
Kapima
Kargoi
Kassay
Kemoh
Kenjama
Kesua
Kimaya
Kendebu
Komboya
Koni
Kpetegonumei
Komende
Konima
Korwama
Kpah
Kpallay
Kpamajama
Kpandobu
Kpangbalia
Kpetema
Kpewama
Kugbahun
LQAS
Lalewahun
Lenga
Levuma
Lifecycle
Lugbu
Lunia
Maboima
Magbao
Manowa
Masahun
Mambawa
Mangaru
Manguama
Manyama
Maryu
Masao
Mawojeh
MoH
Moawoma
Mofindo
Mogbondo
Mokpendeh
Mongere
Mongeri
Morku
Monjemei
Ngao
Ngolamajie
Ngoyiahun
Nguabu
Niawa
Njekohun
Njagbla
Njala
Nyallay
Nyandehun
ORCID
Pelewahun
Pataloo
SLEAC
SQUEAC
Samabobu
Sahn
Samamie
Sannah
Sei
Seilenga
Seiwa
Selenga
Sembehun
Sendeh
Serabu
Sewa
Sewama
Taninahun
Tikonko
Tissawa
Tokpombu
Tolobu
Tongowa
Valunia
Wlihun
Yarlenga
Yeinken
es
kotumahun
Wonde
Yalenga
YawaJu
Yengema
frac
im
lceil
lfloor
nutriverse
offs
salam
quadrat
quadrats
rceil
rfloor
sleac
subdistricts
tibble
undernutrition
3 changes: 2 additions & 1 deletion man/lqas_get_class_prob.Rd

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

9 changes: 7 additions & 2 deletions man/lqas_simulate.Rd

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

17 changes: 13 additions & 4 deletions man/sleacr.Rd

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

0 comments on commit bb4a95a

Please sign in to comment.