Skip to content

Commit

Permalink
refactor calculate_performance(); fix #115
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestguevarra committed Dec 15, 2024
1 parent c83468f commit 10b5b1f
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 54 deletions.
4 changes: 2 additions & 2 deletions R/muac_at_admission.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#' @param na_values A vector of values in `muac` that are to be considered as
#' NA values. Default to NULL which will use NA.
#'
#' @returns A numeric value (if `index = NULL`) or vector of values for median
#' mid-upper arm circumference.
#' @returns A numeric value (if `index = NULL`) or named vector of values for
#' median mid-upper arm circumference with names from each level of `index`.
#'
#' @examples
#' calculate_median_muac(otp_beneficiaries$muac)
Expand Down
30 changes: 16 additions & 14 deletions R/performance.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,29 @@ calculate_performance <- function(df,
add = TRUE) {
## Get vars
if (is.null(vars)) {
## Find variables names in .data
.vars <- c(find_var_names(df, vars = c("cure", "recover")),
find_var_names(df, vars = c("dead", "death")),
find_var_names(df, vars = c("default", "def")),
find_var_names(df, vars = c("response", "respond")))
## Find variables names in df
.vars <- c(
find_var_names(df, vars = c("cure", "recover", "rec")),
find_var_names(df, vars = c("dead", "death")),
find_var_names(df, vars = c("default", "def")),
find_var_names(df, vars = c("response", "respond", "nr"))
)

##
if (any(is.null(.vars))) {
message(
"No variables in `df` match with usual performance indicators data
variable names. First 4 columns of df will be used."
if (all(is.null(.vars))) {
stop(
"No variables in `df` match with usual performance indicators data ",
"variable names. Please check `df` or specify appropriate `vars`.",
call. = TRUE
)

.vars <- names(df)[1:4]
}
} else {
## check if vars found in names of df
if (!all(vars %in% names(df))) {
if (any(!vars %in% names(df))) {
stop(
"Variables in .data does not match with specified variable names in
vars. Try again.", call. = TRUE
"Some or all variables in `df` does not match with specified variable ",
"names in `vars`. Please try again.",
call. = TRUE
)
}

Expand Down
9 changes: 3 additions & 6 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,17 @@ calculate_los_median(otp_beneficiaries$admDate, otp_beneficiaries$disDate)

### CMAM programme coverage

The `{squeacr}` provides functions to calculate programme coverage. These functions implement the single coverage estimator approach[^1]. In this approach, treatment coverage is calculated in such a way that estimates $r_out$ or the number of severe acute malnutrition (SAM) cases that have not been enrolled in the programme but have been recovering without treatment.
The `{squeacr}` provides functions to calculate programme coverage. These functions implement the single coverage estimator approach[^1]. In this approach, treatment coverage is calculated in such a way that estimates the number of severe acute malnutrition (SAM) cases that have not been enrolled in the programme but have been recovering without treatment (`r_out`).

For example, if a coverage survey yielded 5 SAM cases in the programme, 25 cases not in the programme, and 5 recovering cases in the programme, $r_out$ can be calculated as follows:
For example, if a coverage survey yielded 5 SAM cases in the programme, 25 cases not in the programme, and 5 recovering cases in the programme, `r_out` can be calculated as follows:

```{r}
calculate_rout(cin = 5, cout = 25, rin = 5)
```

Note here that the `calculate_rout()` function has another argument named `k` which is a correction factor representing the ratio of the mean length of an untreated episode to the mean length of a CMAM treatment episode. This, by default, is set to `k = 3` in the function. However, this should be adjusted based on programme data to estimate the mean length of a SAM treatment episode.

This calculation for $r_out$ is used within `calculate_tc()` to estimate treatment coverage:
This calculation for `r_out` is used within `calculate_tc()` to estimate treatment coverage:

```{r}
calculate_tc(cin = 5, cout = 25, rin = 5)
Expand All @@ -178,9 +178,6 @@ Feedback, bug reports, and feature requests are welcome; file issues or seek sup

This project is released with a [Contributor Code of Conduct](https://nutriverse.io/squeacr/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.


<br/>

## Footnotes

[^1]: Safari Balegamire, Katja Siling, Jose Luis Alvarez Moran, Ernest Guevarra, Sophie Woodhead, Alison Norris, Lionella Fieschi, Paul Binns, and Mark Myatt (2015). A single coverage estimator for use in SQUEAC, SLEAC, and other CMAM coverage assessments. Field Exchange 49, March 2015. p81. <www.ennonline.net/fex/49/singlecoverage>
46 changes: 20 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,18 @@ monitoring |>
which results in the following:

#> # A tibble: 72 × 7
#> State Year total_discharge cure_rate default_rate death_rate
#> <chr> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 Blue Nile 2016 9693 0.889 0.0906 0.0151
#> 2 Blue Nile 2017 10286 0.948 0.0399 0.00972
#> 3 Blue Nile 2018 8807 0.947 0.0404 0.00863
#> 4 Blue Nile 2019 9882 0.953 0.0366 0.00708
#> 5 Central D… 2016 13313 0.921 0.0440 0.0174
#> 6 Central D… 2017 18098 0.935 0.0421 0.00912
#> 7 Central D… 2018 17600 0.939 0.0364 0.00955
#> 8 Central D… 2019 18573 0.952 0.0260 0.00549
#> 9 East Darf… 2016 9895 0.929 0.0550 0.0104
#> 10 East Darf… 2017 12611 0.956 0.0327 0.00690
#> State Year total_discharge cure_rate default_rate death_rate
#> <chr> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 Blue Nile 2016 9693 0.889 0.0906 0.0151
#> 2 Blue Nile 2017 10286 0.948 0.0399 0.00972
#> 3 Blue Nile 2018 8807 0.947 0.0404 0.00863
#> 4 Blue Nile 2019 9882 0.953 0.0366 0.00708
#> 5 Central Dar… 2016 13313 0.921 0.0440 0.0174
#> 6 Central Dar… 2017 18098 0.935 0.0421 0.00912
#> 7 Central Dar… 2018 17600 0.939 0.0364 0.00955
#> 8 Central Dar… 2019 18573 0.952 0.0260 0.00549
#> 9 East Darfur 2016 9895 0.929 0.0550 0.0104
#> 10 East Darfur 2017 12611 0.956 0.0327 0.00690
#> # ℹ 62 more rows
#> # ℹ 1 more variable: non_response_rate <dbl>

Expand Down Expand Up @@ -221,16 +221,13 @@ which gives the following results:
The `{squeacr}` provides functions to calculate programme coverage.
These functions implement the single coverage estimator approach\[1\].
In this approach, treatment coverage is calculated in such a way that
estimates
![r\_out](https://latex.codecogs.com/png.image?%5Cdpi%7B110%7D&space;%5Cbg_white&space;r_out
"r_out") or the number of severe acute malnutrition (SAM) cases that
have not been enrolled in the programme but have been recovering without
treatment.
estimates the number of severe acute malnutrition (SAM) cases that have
not been enrolled in the programme but have been recovering without
treatment (`r_out`).

For example, if a coverage survey yielded 5 SAM cases in the programme,
25 cases not in the programme, and 5 recovering cases in the programme,
![r\_out](https://latex.codecogs.com/png.image?%5Cdpi%7B110%7D&space;%5Cbg_white&space;r_out
"r_out") can be calculated as follows:
`r_out` can be calculated as follows:

``` r
calculate_rout(cin = 5, cout = 25, rin = 5)
Expand All @@ -244,9 +241,8 @@ treatment episode. This, by default, is set to `k = 3` in the function.
However, this should be adjusted based on programme data to estimate the
mean length of a SAM treatment episode.

This calculation for
![r\_out](https://latex.codecogs.com/png.image?%5Cdpi%7B110%7D&space;%5Cbg_white&space;r_out
"r_out") is used within `calculate_tc()` to estimate treatment coverage:
This calculation for `r_out` is used within `calculate_tc()` to estimate
treatment coverage:

``` r
calculate_tc(cin = 5, cout = 25, rin = 5)
Expand All @@ -266,8 +262,8 @@ citation("squeacr")
#> Allison, Guerrero, Saul, Schofield, Lilly, Jones, Daniel,
#> Emru, Ephrem, Sadler, Kate (2012). _Semi-Quantitative
#> Evaluation of Access and Coverage (SQUEAC)/Simplified Lot
#> Quality Assurance Sampling Evaluation of Access and
#> Coverage (SLEAC) Technical Reference_.
#> Quality Assurance Sampling Evaluation of Access and Coverage
#> (SLEAC) Technical Reference_.
#> <https://www.fantaproject.org/sites/default/files/resources/SQUEAC-SLEAC-Technical-Reference-Oct2012_0.pdf>.
#>
#> A BibTeX entry for LaTeX users is
Expand Down Expand Up @@ -296,8 +292,6 @@ contributing to this project, you agree to abide by its terms.

<br/>

## Footnotes

1. Safari Balegamire, Katja Siling, Jose Luis Alvarez Moran, Ernest
Guevarra, Sophie Woodhead, Alison Norris, Lionella Fieschi, Paul
Binns, and Mark Myatt (2015). A single coverage estimator for use in
Expand Down
4 changes: 2 additions & 2 deletions man/calculate_median_muac.Rd

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

1 change: 1 addition & 0 deletions pkgdown/_pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ development:
template:
bootstrap: 5
theme: breeze-light
math-rendering: katex
ganalytics: "G-C6TYX2E6RD"
bslib:
bootswatch: pulse
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-performance.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ test_that("warning/error is activated", {
df = monitoring, vars = c("healed", "died", "missing", "no_recovery")
)
)
expect_message(calculate_performance(df = x))
expect_error(calculate_performance(df = x))
expect_error(calculate_performance(y1))
expect_error(calculate_performance(y2))
expect_error(calculate_performance(y3))
Expand Down
8 changes: 5 additions & 3 deletions vignettes/squeacr.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ vignette: >
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
message = FALSE,
comment = "#>"
)
```
Expand Down Expand Up @@ -140,20 +141,21 @@ calculate_los_median(otp_beneficiaries$admDate, otp_beneficiaries$disDate)

### CMAM programme coverage

The `{squeacr}` provides functions to calculate programme coverage. These functions implement the single coverage estimator approach[^1]. In this approach, treatment coverage is calculated in such a way that estimates $r_{out}$ or the number of severe acute malnutrition (SAM) cases that have not been enrolled in the programme but have been recovering without treatment.
The `{squeacr}` provides functions to calculate programme coverage. These functions implement the single coverage estimator approach[^1]. In this approach, treatment coverage is calculated in such a way that estimates the number of severe acute malnutrition (SAM) cases that have not been enrolled in the programme but have been recovering without treatment (`r_out`).

For example, if a coverage survey yielded 5 SAM cases in the programme, 25 cases not in the programme, and 5 recovering cases in the programme, $r_{out}$ can be calculated as follows:
For example, if a coverage survey yielded 5 SAM cases in the programme, 25 cases not in the programme, and 5 recovering cases in the programme, `r_out` can be calculated as follows:

```{r}
calculate_rout(cin = 5, cout = 25, rin = 5)
```

Note here that the `calculate_rout()` function has another argument named `k` which is a correction factor representing the ratio of the mean length of an untreated episode to the mean length of a CMAM treatment episode. This, by default, is set to `k = 3` in the function. However, this should be adjusted based on programme data to estimate the mean length of a SAM treatment episode.

This calculation for $r_{out}$ is used within `calculate_tc()` to estimate treatment coverage:
This calculation for `r_out` is used within `calculate_tc()` to estimate treatment coverage:

```{r}
calculate_tc(cin = 5, cout = 25, rin = 5)
```


[^1]: Safari Balegamire, Katja Siling, Jose Luis Alvarez Moran, Ernest Guevarra, Sophie Woodhead, Alison Norris, Lionella Fieschi, Paul Binns, and Mark Myatt (2015). A single coverage estimator for use in SQUEAC, SLEAC, and other CMAM coverage assessments. Field Exchange 49, March 2015. p81. <www.ennonline.net/fex/49/singlecoverage>

0 comments on commit 10b5b1f

Please sign in to comment.