Skip to content

Commit f705778

Browse files
Merge pull request #93 from nutriverse/dev
add squeacr functions as utilities; remove squeacr dependency
2 parents 655b1a3 + 484ac87 commit f705778

9 files changed

Lines changed: 80 additions & 10 deletions

DESCRIPTION

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ Imports:
3333
methods,
3434
parallel,
3535
parallelly,
36-
squeacr,
3736
stats
3837
Suggests:
3938
covr,
@@ -42,8 +41,6 @@ Suggests:
4241
spelling,
4342
testthat (>= 3.0.0),
4443
tibble
45-
Remotes:
46-
rapidsurveys/squeacr
4744
Encoding: UTF-8
4845
Language: en-GB
4946
LazyData: true

R/03-classify_coverage.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
#' are in the CMAM programme.
88
#' @param rec_in Number of children recovering from SAM or MAM found during the
99
#' survey who are in the programme.
10-
#' @inheritParams squeacr::calculate_tc
10+
#' @param k Correction factor. Ratio of the mean length of an untreated episode
11+
#' to the mean length of a CMAM treatment episode
1112
#' @param threshold Decision rule threshold/s. Should be between 0 and 1. At
1213
#' least one threshold should be provided for a two-tier classifier. Two
1314
#' thresholds should be provided for a three-tier classifier. Default is a
@@ -150,7 +151,7 @@ lqas_classify_cf <- function(cases_in, cases_out,
150151

151152
lqas_classify_tc <- function(cases_in, cases_out, rec_in, k,
152153
threshold = c(0.2, 0.5), label = FALSE) {
153-
rec_out <- squeacr::calculate_rout(cases_in, cases_out, rec_in, k = k)
154+
rec_out <- calculate_rout(cases_in, cases_out, rec_in, k = k)
154155

155156
d <- (cases_in + cases_out + rec_in + rec_out) * threshold
156157

R/05-post_strat_estimator.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
#' @param u5 A numeric value for the proportion of the population that is under
2121
#' years old.
2222
#' @param p Prevalence of SAM or MAM in the given population.
23+
#' @param k Correction factor. Ratio of the mean length of an untreated episode
24+
#' to the mean length of a CMAM treatment episode
2325
#' @param cov_type Coverage estimator to report. Either *"cf"* for
2426
#' *case-finding effectiveness* or *"tc"* for *treatment coverage*.
2527
#' Default is *"cf"*.
26-
#' @inheritParams squeacr::calculate_tc
2728
#'
2829
#' @returns A list of overall coverage estimates with corresponding 95%
2930
#' confidence intervals for case-finding effectiveness and treatment coverage.
@@ -141,11 +142,11 @@ estimate_coverage <- function(cov_df,
141142
cov_type <- match.arg(cov_type)
142143

143144
if (cov_type == "cf") {
144-
cov <- with(cov_df, squeacr::calculate_cf(cin = cases_in, cout = cases_out))
145+
cov <- with(cov_df, calculate_cf(cin = cases_in, cout = cases_out))
145146
} else {
146147
cov <- with(
147148
cov_df,
148-
squeacr::calculate_tc(
149+
calculate_tc(
149150
cin = cases_in, cout = cases_out, rin = rec_in, k = k
150151
)
151152
)
@@ -166,7 +167,7 @@ calculate_ci <- function(cov_df, cov_type = c("cf", "tc"), k = 3, weights) {
166167
} else {
167168
rec_out <- with(
168169
cov_df,
169-
squeacr::calculate_rout(cases_in, cases_out, rec_in, k = k)
170+
calculate_rout(cases_in, cases_out, rec_in, k = k)
170171
)
171172

172173
c <- cov_df$cases_in + cov_df$rec_in

R/06-chi-square.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ calculate_x2_stat <- function(cases_in, cases_out, rec_in, k = 3) {
9292
observed_tc <- cases_in + rec_in
9393

9494
## Calculate rec_out ----
95-
rec_out <- squeacr::calculate_rout(
95+
rec_out <- calculate_rout(
9696
cin = cases_in, cout = cases_out, rin = rec_in, k = k
9797
)
9898

R/utils.R

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,37 @@ check_p <- function(p) {
169169
}
170170

171171

172+
#'
173+
#' Calculate r_out
174+
#'
175+
#' @keywords internal
176+
#'
177+
178+
calculate_rout <- function(cin, cout, rin, k = 3) {
179+
floor((1 / k) * (rin * ((cin + 1 + cout) / (cin + 1)) - rin))
180+
}
181+
182+
183+
#'
184+
#' Calculate case-finding effectiveness
185+
#'
186+
#' @keywords internal
187+
#'
188+
189+
calculate_cf <- function(cin, cout) {
190+
cin / (cin + cout)
191+
}
192+
193+
194+
#'
195+
#' Calculate treatment coverage
196+
#'
197+
#' @keywords internal
198+
#'
199+
200+
calculate_tc <- function(cin, cout, rin, k = 3) {
201+
rout <- calculate_rout(cin = cin, cout = cout, rin = rin, k = k)
202+
(cin + rin) / (cin + cout + rin + rout)
203+
}
204+
172205

man/calculate_cf.Rd

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/calculate_rout.Rd

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/calculate_tc.Rd

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@
99
library(testthat)
1010
library(sleacr)
1111

12+
set.seed(1972)
13+
1214
test_check("sleacr")

0 commit comments

Comments
 (0)