diff --git a/NEWS.md b/NEWS.md index a44c0e4..3aadaec 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# oldr 0.2.1 + + + # oldr 0.1.1 * Created full suite of estimator functions diff --git a/R/01-opIndicators.R b/R/01-opIndicators.R index 4298f89..4878b6a 100644 --- a/R/01-opIndicators.R +++ b/R/01-opIndicators.R @@ -287,7 +287,8 @@ #' `wgP3` | Overall 3 #' `wgPM` | Any disability #' -#' @param svy A data.frame collected using the standard RAM-OP questionnaire +#' @param svy A [data.frame()] collected using the standard RAM-OP +#' questionnaire. #' @param indicators A character vector of indicator set names. The vector may #' include one or more of the following: *"demo"*, *"food"*, *"hunger"*, #' *"disability"*, *"adl"*, *"mental"*, *"dementia"*, *"health"*, *"income"*, @@ -297,7 +298,7 @@ #' to report indicators for *males*, *females*, or *both* respectively. #' Default is *"mf"* for both sexes. #' -#' @return A tibble of older people indicators +#' @return A [tibble()] of older people indicators. #' #' @examples #' # Create indicators dataset from RAM-OP survey data collected from diff --git a/R/02-classicBoot.R b/R/02-classicBoot.R index 03ada8d..0353685 100644 --- a/R/02-classicBoot.R +++ b/R/02-classicBoot.R @@ -2,11 +2,11 @@ #' Apply bootstrap to RAM-OP indicators using a classical estimator. #' #' @param x Indicators dataset produced by [create_op()] with primary sampling -#' unit (PSU) in column named `psu` -#' @param w A data frame with primary sampling unit (PSU) in column named `psu` -#' and survey weight (i.e. PSU population) in column named `pop` -#' @param statistic A function operating on data in `x`. Fixed to `bootClassic()` -#' function for means +#' unit (PSU) in column named *"psu"*. +#' @param w A data frame with primary sampling unit (PSU) in column named +#' *"psu"* and survey weight (i.e. PSU population) in column named *"pop"*. +#' @param statistic A function operating on data in `x`. Fixed to +#' [bootClassic()] function for means. #' @param indicators A character vector of indicator set names to estimate. #' Indicator set names are *"demo"*, *"food"*, *"hunger"*, *"disability"*, #' *"adl"*, *"mental"*, *"dementia"*, *"health"*, *"income"*, *"wash"*, diff --git a/R/03-probitBoot.R b/R/03-probitBoot.R index fef7a10..7a1c43b 100644 --- a/R/03-probitBoot.R +++ b/R/03-probitBoot.R @@ -2,21 +2,20 @@ #' Apply bootstrap to RAM-OP indicators using a PROBIT estimator. #' #' @param x Indicators dataset produced by [create_op()] with primary sampling -#' unit (PSU) in column named `PSU` +#' unit (PSU) in column named *"psu"*. #' @param w A data frame with primary sampling unit (PSU) in column named -#' `psu` and survey weight (i.e. PSU population) in column named `pop`. +#' *"psu"* and survey weight (i.e. PSU population) in column named *"pop"*. #' @param gam.stat A function operating on data in `x` to estimate GAM -#' prevalence for older people. Fixed to `probit_gam` +#' prevalence for older people. Fixed to [probit_gam()]. #' @param sam.stat A function operating on data in `x` to estimate -#' SAM prevalence for older people. Fixed to `probit_sam` +#' SAM prevalence for older people. Fixed to [probit_sam()]. #' @param params Parameters (named columns in `x`) passed to the function -#' specified in `statistic`; fixed to `MUAC` as indicator amenable -#' to probit estimation -#' @param outputColumns Names of columns in output data frame; fixed to -#' `MUAC` -#' @param replicates Number of bootstrap replicate case and non-case +#' specified in `statistic`; fixed to *"MUAC"* as indicator amenable +#' to probit estimation. +#' @param outputColumns Names of columns in output data frame. +#' @param replicates Number of bootstrap replicate case and non-case. #' -#' @return A tibble of boot estimates using bootPROBIT function +#' @return A [tibble()] of boot estimates using PROBIT. #' #' @examples #' test <- estimate_probit(x = indicators.ALL, w = testPSU, replicates = 3) @@ -31,58 +30,46 @@ estimate_probit <- function(x, gam.stat = probit_gam, sam.stat = probit_sam, params = "MUAC", - outputColumns = "MUAC", + outputColumns = params, replicates = 399) { ## Blocking weighted bootstrap (GAM) - ALL - bootGAM.ALL <- bbw::bootBW(x = x, - w = w, - statistic = gam.stat, - params = params, - outputColumns = params, - replicates = replicates) + bootGAM.ALL <- bootBW( + x = x, w = w, statistic = gam.stat, params = params, + outputColumns = params, replicates = replicates + ) ## Blocking weighted bootstrap (GAM) - MALES - bootGAM.MALES <- bbw::bootBW(x = x[x$sex1 == 1, ], - w = w, - statistic = gam.stat, - params = params, - outputColumns = params, - replicates = replicates) + bootGAM.MALES <- bootBW( + x = x[x$sex1 == 1, ], w = w, statistic = gam.stat, params = params, + outputColumns = params, replicates = replicates + ) ## Blocking weighted bootstrap (GAM) - FEMALES - bootGAM.FEMALES <- bbw::bootBW(x = x[x$sex2 == 1, ], - w = w, - statistic = gam.stat, - params = params, - outputColumns = params, - replicates = replicates) + bootGAM.FEMALES <- bootBW( + x = x[x$sex2 == 1, ], w = w, statistic = gam.stat, params = params, + outputColumns = params, replicates = replicates + ) ## Rename results names(bootGAM.ALL) <- names(bootGAM.MALES) <- names(bootGAM.FEMALES) <- "GAM" ## Blocking weighted bootstrap (SAM) - ALL - bootSAM.ALL <- bbw::bootBW(x = x, - w = w, - statistic = sam.stat, - params = params, - outputColumns = params, - replicates = replicates) + bootSAM.ALL <- bootBW( + x = x, w = w, statistic = sam.stat, params = params, + outputColumns = params, replicates = replicates + ) ## Blocking weighted bootstrap (SAM) - MALES - bootSAM.MALES <- bbw::bootBW(x = x[x$sex1 ==1, ], - w = w, - statistic = sam.stat, - params = params, - outputColumns = params, - replicates = replicates) + bootSAM.MALES <- bootBW( + x = x[x$sex1 ==1, ], w = w, statistic = sam.stat, params = params, + outputColumns = params, replicates = replicates + ) ## Blocking weighted bootstrap (SAM) - FEMALES - bootSAM.FEMALES <- bbw::bootBW(x = x[x$sex2 ==1, ], - w = w, - statistic = sam.stat, - params = params, - outputColumns = params, - replicates = replicates) + bootSAM.FEMALES <- bootBW( + x = x[x$sex2 ==1, ], w = w, statistic = sam.stat, params = params, + outputColumns = params, replicates = replicates + ) ## Rename results names(bootSAM.ALL) <- names(bootSAM.MALES) <- names(bootSAM.FEMALES) <- "SAM" @@ -111,37 +98,46 @@ estimate_probit <- function(x, ## Extract estimates from 'boot.ALL' data.frames estimates.ALL <- data.frame( - t(apply(X = boot.ALL, - MARGIN = 2, - FUN = quantile, - probs = c(0.025, 0.5, 0.975), na.rm = TRUE))) + t( + apply( + X = boot.ALL, MARGIN = 2, FUN = quantile, + probs = c(0.025, 0.5, 0.975), na.rm = TRUE + ) + ) + ) ## Extract estimates from 'boot.MALES' data.frames estimates.MALES <- data.frame( - t(apply(X = boot.MALES, - MARGIN = 2, - FUN = quantile, - probs = c(0.025, 0.5, 0.975), na.rm = TRUE))) + t( + apply( + X = boot.MALES, MARGIN = 2, FUN = quantile, + probs = c(0.025, 0.5, 0.975), na.rm = TRUE + ) + ) + ) ## Extract estimates from 'boot.FEMALES' data.frames estimates.FEMALES <- data.frame( - t(apply(X = boot.FEMALES, - MARGIN = 2, - FUN = quantile, - probs = c(0.025, 0.5, 0.975), na.rm = TRUE))) + t( + apply( + X = boot.FEMALES, MARGIN = 2, FUN = quantile, + probs = c(0.025, 0.5, 0.975), na.rm = TRUE + ) + ) + ) ## Join 'estimates.*' data.frames side-by-side - probitEstimates <- data.frame(estimates.ALL, - estimates.MALES, - estimates.FEMALES) + probitEstimates <- data.frame( + estimates.ALL, estimates.MALES, estimates.FEMALES + ) ## Clean-up row and column names probitEstimates$indicator <- row.names(probitEstimates) row.names(probitEstimates) <- NULL - names(probitEstimates) <- c("LCL.ALL", "EST.ALL", "UCL.ALL", - "LCL.MALES", "EST.MALES", "UCL.MALES", - "LCL.FEMALES", "EST.FEMALES", "UCL.FEMALES", - "INDICATOR") + names(probitEstimates) <- c( + "LCL.ALL", "EST.ALL", "UCL.ALL", "LCL.MALES", "EST.MALES", "UCL.MALES", + "LCL.FEMALES", "EST.FEMALES", "UCL.FEMALES", "INDICATOR" + ) ## Re-order columns col_order <- c( diff --git a/R/04-probit_muac.R b/R/04-probit_muac.R index e23fc67..43db11f 100644 --- a/R/04-probit_muac.R +++ b/R/04-probit_muac.R @@ -1,13 +1,14 @@ #' #' PROBIT statistics function for bootstrap estimation of older people GAM #' -#' @param x A data frame with `primary sampling unit (PSU)` in column named -#' `psu` and with data column/s containing the continuous variable/s of +#' @param x A data frame with primary sampling unit (PSU) in column named +#' *"psu"* and with data column/s containing the continuous variable/s of #' interest with column names corresponding to `params` values #' @param params A vector of column names corresponding to the continuous #' variables of interest contained in `x` #' @param threshold cut-off value for continuous variable to differentiate -#' case and non-case. Default is set at 210. +#' case and non-case. Default is set at 210 for [probit_gam()] and 185 for +#' [probit_sam()]. #' #' @return A numeric vector of the PROBIT estimate of each continuous variable #' of interest with length equal to `length(params)` diff --git a/R/06-estimate_op.R b/R/06-estimate_op.R index 48ab0d7..4d37854 100644 --- a/R/06-estimate_op.R +++ b/R/06-estimate_op.R @@ -2,16 +2,17 @@ #' Estimate all standard RAM-OP indicators #' #' @param x Indicators dataset produced by [create_op()] with primary sampling -#' unit (PSU) in column named `PSU` +#' unit (PSU) in column named *"psu"*` #' @param w A data frame with primary sampling unit (PSU) in column named -#' `psu` and survey weight (i.e. PSU population) in column named `pop` +#' *"psu"* and survey weight (i.e. PSU population) in column named *"pop"*. #' @param indicators A character vector of indicator set names to estimate. #' Indicator set names are *"demo"*, *"anthro"*, *"food"*, *"hunger"*, #' *"disability"*, *"adl"*, *"mental"*, *"dementia"*, *"health"*, *"income"*, #' *"wash"*, *"visual"*, and *"misc"*. Default is all indicator sets. #' @param replicates Number of bootstrap replicates. Default is 399. #' -#' @return Tibble of boot estimates for all specified standard RAM-OP indicators +#' @return A [tibble()] of boot estimates for all specified standard RAM-OP +#' indicators #' #' @examples #' estimate_op(x = create_op(testSVY), w = testPSU, replicates = 9) diff --git a/inst/WORDLIST b/inst/WORDLIST index 415ee01..bb5c9b9 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -11,13 +11,11 @@ Codecov Colpe DDS DK -DS Deitchler Dop EpiData FANTA FAO -FG FHI Grotz HH @@ -31,7 +29,6 @@ Jaffe LJ Lifecycle MAM -MF MUAC Moskowitz Mroczek @@ -49,34 +46,21 @@ RW RapidSurveys SLT TD -Tibble WG adl anthro bootClassic -bootPROBIT cd ci -classADL codecov etc frac -hasHelp mf moringa poorVA psu -resp -scoreADL +ramOP +ramOPreport th tibble -unmetNeed -wgCommunicatingD -wgHearingD -wgMobilityD -wgP -wgPM -wgRememberingD -wgSelfCareD -wgVisionD widehat diff --git a/man/create_op.Rd b/man/create_op.Rd index f4316ff..048c1af 100644 --- a/man/create_op.Rd +++ b/man/create_op.Rd @@ -58,7 +58,8 @@ create_op_visual(svy, sex = c("mf", "m", "f")) create_op_misc(svy, sex = c("mf", "m", "f")) } \arguments{ -\item{svy}{A data.frame collected using the standard RAM-OP questionnaire} +\item{svy}{A \code{\link[=data.frame]{data.frame()}} collected using the standard RAM-OP +questionnaire.} \item{indicators}{A character vector of indicator set names. The vector may include one or more of the following: \emph{"demo"}, \emph{"food"}, \emph{"hunger"}, @@ -71,7 +72,7 @@ to report indicators for \emph{males}, \emph{females}, or \emph{both} respective Default is \emph{"mf"} for both sexes.} } \value{ -A tibble of older people indicators +A \code{\link[=tibble]{tibble()}} of older people indicators. } \description{ The indicator sets covered by the standard RAM-OP survey are: diff --git a/man/estimate_classic.Rd b/man/estimate_classic.Rd index 60a4d5f..0970060 100644 --- a/man/estimate_classic.Rd +++ b/man/estimate_classic.Rd @@ -17,13 +17,13 @@ estimate_classic( } \arguments{ \item{x}{Indicators dataset produced by \code{\link[=create_op]{create_op()}} with primary sampling -unit (PSU) in column named \code{psu}} +unit (PSU) in column named \emph{"psu"}.} -\item{w}{A data frame with primary sampling unit (PSU) in column named \code{psu} -and survey weight (i.e. PSU population) in column named \code{pop}} +\item{w}{A data frame with primary sampling unit (PSU) in column named +\emph{"psu"} and survey weight (i.e. PSU population) in column named \emph{"pop"}.} -\item{statistic}{A function operating on data in \code{x}. Fixed to \code{bootClassic()} -function for means} +\item{statistic}{A function operating on data in \code{x}. Fixed to +\code{\link[=bootClassic]{bootClassic()}} function for means.} \item{indicators}{A character vector of indicator set names to estimate. Indicator set names are \emph{"demo"}, \emph{"food"}, \emph{"hunger"}, \emph{"disability"}, diff --git a/man/estimate_op.Rd b/man/estimate_op.Rd index 2d61c7c..3376af1 100644 --- a/man/estimate_op.Rd +++ b/man/estimate_op.Rd @@ -14,10 +14,10 @@ estimate_op( } \arguments{ \item{x}{Indicators dataset produced by \code{\link[=create_op]{create_op()}} with primary sampling -unit (PSU) in column named \code{PSU}} +unit (PSU) in column named \emph{"psu"}`} \item{w}{A data frame with primary sampling unit (PSU) in column named -\code{psu} and survey weight (i.e. PSU population) in column named \code{pop}} +\emph{"psu"} and survey weight (i.e. PSU population) in column named \emph{"pop"}.} \item{indicators}{A character vector of indicator set names to estimate. Indicator set names are \emph{"demo"}, \emph{"anthro"}, \emph{"food"}, \emph{"hunger"}, @@ -27,7 +27,8 @@ Indicator set names are \emph{"demo"}, \emph{"anthro"}, \emph{"food"}, \emph{"hu \item{replicates}{Number of bootstrap replicates. Default is 399.} } \value{ -Tibble of boot estimates for all specified standard RAM-OP indicators +A \code{\link[=tibble]{tibble()}} of boot estimates for all specified standard RAM-OP +indicators } \description{ Estimate all standard RAM-OP indicators diff --git a/man/estimate_probit.Rd b/man/estimate_probit.Rd index 4ecc91b..4121fda 100644 --- a/man/estimate_probit.Rd +++ b/man/estimate_probit.Rd @@ -10,34 +10,33 @@ estimate_probit( gam.stat = probit_gam, sam.stat = probit_sam, params = "MUAC", - outputColumns = "MUAC", + outputColumns = params, replicates = 399 ) } \arguments{ \item{x}{Indicators dataset produced by \code{\link[=create_op]{create_op()}} with primary sampling -unit (PSU) in column named \code{PSU}} +unit (PSU) in column named \emph{"psu"}.} \item{w}{A data frame with primary sampling unit (PSU) in column named -\code{psu} and survey weight (i.e. PSU population) in column named \code{pop}.} +\emph{"psu"} and survey weight (i.e. PSU population) in column named \emph{"pop"}.} \item{gam.stat}{A function operating on data in \code{x} to estimate GAM -prevalence for older people. Fixed to \code{probit_gam}} +prevalence for older people. Fixed to \code{\link[=probit_gam]{probit_gam()}}.} \item{sam.stat}{A function operating on data in \code{x} to estimate -SAM prevalence for older people. Fixed to \code{probit_sam}} +SAM prevalence for older people. Fixed to \code{\link[=probit_sam]{probit_sam()}}.} \item{params}{Parameters (named columns in \code{x}) passed to the function -specified in \code{statistic}; fixed to \code{MUAC} as indicator amenable -to probit estimation} +specified in \code{statistic}; fixed to \emph{"MUAC"} as indicator amenable +to probit estimation.} -\item{outputColumns}{Names of columns in output data frame; fixed to -\code{MUAC}} +\item{outputColumns}{Names of columns in output data frame.} -\item{replicates}{Number of bootstrap replicate case and non-case} +\item{replicates}{Number of bootstrap replicate case and non-case.} } \value{ -A tibble of boot estimates using bootPROBIT function +A \code{\link[=tibble]{tibble()}} of boot estimates using PROBIT. } \description{ Apply bootstrap to RAM-OP indicators using a PROBIT estimator. diff --git a/man/op_probit.Rd b/man/op_probit.Rd index 6baf93b..a638a8d 100644 --- a/man/op_probit.Rd +++ b/man/op_probit.Rd @@ -10,15 +10,16 @@ probit_gam(x, params, threshold = 210) probit_sam(x, params, threshold = 185) } \arguments{ -\item{x}{A data frame with \verb{primary sampling unit (PSU)} in column named -\code{psu} and with data column/s containing the continuous variable/s of +\item{x}{A data frame with primary sampling unit (PSU) in column named +\emph{"psu"} and with data column/s containing the continuous variable/s of interest with column names corresponding to \code{params} values} \item{params}{A vector of column names corresponding to the continuous variables of interest contained in \code{x}} \item{threshold}{cut-off value for continuous variable to differentiate -case and non-case. Default is set at 210.} +case and non-case. Default is set at 210 for \code{\link[=probit_gam]{probit_gam()}} and 185 for +\code{\link[=probit_sam]{probit_sam()}}.} } \value{ A numeric vector of the PROBIT estimate of each continuous variable