Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setup new theme and other website setup #144

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
^vignettes/sample_size_files$
ˆvignettes/sample_size.html$
^CODE_OF_CONDUCT\.md$
^vignettes/\.quarto$
53 changes: 53 additions & 0 deletions .github/workflows/netlify.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
on:
pull_request:
branches: [main, master]

name: pkgdown-pr

jobs:
netlify:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-tinytex@v2

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
needs: website

- name: Install package
run: R CMD INSTALL .

- name: Create website
run: |
pkgdown::build_site()
shell: Rscript {0}

- name: Create index file
run: |
echo '<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0;URL=/dev/index.html" /> <script language="javascript"> window.location.replace('/dev/index.html')</script></head></html>' > ./docs/index.html

- name: Deploy to Netlify
uses: nwtgck/[email protected]
with:
publish-dir: './docs'
production-branch: main
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy-message:
'Deploy from GHA: ${{ github.event.pull_request.title || github.event.head_commit.message }} (${{ github.sha }})'
# these default to 'true'
enable-commit-comment: false
enable-github-deployment: false
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
1 change: 0 additions & 1 deletion .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ docs
/vignettes/plausibility_files/
/vignettes/prevalence_files/
/vignettes/sample_size_files/
/vignettes/.quarto/

/.quarto/


data-raw/ENA_generated_zscores.csv
data-raw/ENA_generated_zscores.csv
/doc/
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Type: Package
Package: mwana
Title: An Efficient Workflow for Plausibility Checks and Prevalence Analysis of
Wasting in R
Version: 0.2.1
Version: 0.2.1.9000
Authors@R: c(
person("Tomás", "Zaba", , "[email protected]",
role = c("aut", "cre", "cph"),
Expand Down
55 changes: 29 additions & 26 deletions R/prev_wasting_combined.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ complex_survey_estimates_combined <- function(df,
)
}

## Create survey object ----
## Filter out flags ----
df <- dplyr::filter(.data = df, .data$cflags == 0)

## Create a survey object for a weighted analysis ----
if (!quo_is_null(wt)) {
srvy <- srvyr::as_survey_design(
.data = df,
Expand All @@ -51,6 +54,7 @@ complex_survey_estimates_combined <- function(df,
weights = !!wt
)
} else {
## Create a survey object for an unweighted analysis ----
srvy <- srvyr::as_survey_design(
.data = df,
ids = .data$cluster,
Expand All @@ -59,13 +63,12 @@ complex_survey_estimates_combined <- function(df,
)
}
## Summarise prevalence ----
p <- dplyr::group_by(.data = srvy, {{ .by }}) |>
dplyr::filter(.data$cflags == 0) |>
dplyr::summarise(
dplyr::across(
p <- srvyr::group_by(.data = srvy, {{ .by }}) |>
srvyr::summarise(
srvyr::across(
.data$cgam:.data$cmam,
list(
n = \(.) sum(., na.rm = TRUE),
n = ~sum(.x, na.rm = TRUE),
p = \(.) srvyr::survey_mean(
.,
vartype = "ci",
Expand All @@ -87,44 +90,44 @@ complex_survey_estimates_combined <- function(df,
#'
#' @description
#' Estimate the prevalence of wasting based on the combined case-definition of
#' weight-for-height z-scores (WFHZ), MUAC and/or edema. The function allows
#' users to estimate prevalence in accordance with complex sample design
#' properties such as accounting for survey sample weights when needed or
#' applicable. The quality of the data is first evaluated by calculating and
#' rating the standard deviation of WFHZ and MFAZ and the p-value of the age
#' ratio test. Prevalence is calculated only when all tests are rated as not
#' problematic. If any of the tests rate as problematic, no estimation is done
#' and an NA value is returned. Outliers are detected in both WFHZ and MFAZ
#' datasets based on SMART flagging criteria. Identified outliers are then
#' weight-for-height z-scores (WFHZ), MUAC and/or edema. The function allows
#' users to estimate prevalence in accordance with complex sample design
#' properties such as accounting for survey sample weights when needed or
#' applicable. The quality of the data is first evaluated by calculating and
#' rating the standard deviation of WFHZ and MFAZ and the p-value of the age
#' ratio test. Prevalence is calculated only when all tests are rated as not
#' problematic. If any of the tests rate as problematic, no estimation is done
#' and an NA value is returned. Outliers are detected in both WFHZ and MFAZ
#' datasets based on SMART flagging criteria. Identified outliers are then
#' excluded before prevalence estimation is performed.
#'
#' @param df A `tibble` object produced by sequential application of the
#' [mw_wrangle_wfhz()] and [mw_wrangle_muac()]. Note that MUAC values in `df`
#' [mw_wrangle_wfhz()] and [mw_wrangle_muac()]. Note that MUAC values in `df`
#' must be in millimeters unit after using [mw_wrangle_muac()]. Also, `df`
#' must have a variable called `cluster` which contains the primary sampling
#' unit identifiers.
#'
#' @param wt A vector of class `double` of the survey sampling weights. Default
#' is NULL which assumes a self-weighted survey as is the case for a survey
#' @param wt A vector of class `double` of the survey sampling weights. Default
#' is NULL which assumes a self-weighted survey as is the case for a survey
#' sample selected proportional to population size (i.e., SMART survey sample).
#' Otherwise, a weighted analysis is implemented.
#'
#' @param edema A `character` vector for presence of nutritional edema coded as
#' "y" for presence of nutritional edema and "n" for absence of nutritional
#' "y" for presence of nutritional edema and "n" for absence of nutritional
#' edema. Default is NULL.
#'
#' @param .by A `character` or `numeric` vector of the geographical areas
#' or identifiers for where the data was collected and for which the analysis
#' should be summarised for.
#'
#' @returns A summary `tibble` for the descriptive statistics about combined
#' @returns A summary `tibble` for the descriptive statistics about combined
#' wasting.
#'
#' @details
#' A concept of *combined flags* is introduced in this function. Any observation
#' that is flagged for either `flag_wfhz` or `flag_mfaz` is flagged under a new
#' variable named `cflags` added to `df`. This ensures that all flagged
#' observations from both WFHZ and MFAZ data are excluded from the prevalence
#' variable named `cflags` added to `df`. This ensures that all flagged
#' observations from both WFHZ and MFAZ data are excluded from the prevalence
#' analysis.
#'
#' | **flag_wfhz** | **flag_mfaz** | **cflags** |
Expand Down Expand Up @@ -174,7 +177,7 @@ mw_estimate_prevalence_combined <- function(df,
.data = df,
std_wfhz = rate_std(
stats::sd(
remove_flags(as.numeric(.data$wfhz), "zscores"),
remove_flags(as.numeric(.data$wfhz), "zscores"),
na.rm = TRUE
)
),
Expand All @@ -183,7 +186,7 @@ mw_estimate_prevalence_combined <- function(df,
),
std_mfaz = rate_std(
stats::sd(
remove_flags(as.numeric(.data$mfaz), "zscores"),
remove_flags(as.numeric(.data$mfaz), "zscores"),
na.rm = TRUE)
),
muac_analysis_path = set_analysis_path(.data$age_ratio, .data$std_mfaz),
Expand All @@ -195,7 +198,7 @@ mw_estimate_prevalence_combined <- function(df,
.data = df,
std_wfhz = rate_std(
stats::sd(
remove_flags(as.numeric(.data$wfhz), "zscores"),
remove_flags(as.numeric(.data$wfhz), "zscores"),
na.rm = TRUE
)
),
Expand All @@ -204,7 +207,7 @@ mw_estimate_prevalence_combined <- function(df,
),
std_mfaz = rate_std(
stats::sd(
remove_flags(as.numeric(.data$mfaz), "zscores"),
remove_flags(as.numeric(.data$mfaz), "zscores"),
na.rm = TRUE
)
),
Expand Down
37 changes: 20 additions & 17 deletions R/prev_wasting_mfaz.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ complex_survey_estimates_mfaz <- function(df,
)
}

## Create a survey object ----
## Filter out flags ----
df <- dplyr::filter(.data = df, .data$flag_mfaz == 0)

## Create a survey object for a weighted analysis ----
if (!is.null(wt)) {
srvy <- srvyr::as_survey_design(
.data = df,
Expand All @@ -36,6 +39,7 @@ complex_survey_estimates_mfaz <- function(df,
weights = {{ wt }}
)
} else {
## Create a survey object for an unweighted analysis ----
srvy <- srvyr::as_survey_design(
.data = df,
ids = .data$cluster,
Expand All @@ -45,10 +49,9 @@ complex_survey_estimates_mfaz <- function(df,
}

## Summarise prevalence ----
p <- dplyr::group_by(.data = srvy, {{ .by }}) |>
dplyr::filter(.data$flag_mfaz == 0) |>
dplyr::summarise(
dplyr::across(
p <- srvyr::group_by(.data = srvy, {{ .by }}) |>
srvyr::summarise(
srvyr::across(
.data$gam:.data$mam,
list(
n = \(.) sum(., na.rm = TRUE),
Expand All @@ -72,29 +75,29 @@ complex_survey_estimates_mfaz <- function(df,
#' Estimate the prevalence of wasting based on z-scores of muac-for-age (MFAZ)
#'
#' @description
#' Calculate the prevalence estimates of wasting based on z-scores of
#' MUAC-for-age and/or bilateral edema. The function allows users to estimate
#' prevalence in accordance with complex sample design properties such as
#' accounting for survey sample weights when needed or applicable. The quality
#' of the data is first evaluated by calculating and rating the standard
#' deviation of MFAZ. Standard approach to prevalence estimation is calculated
#' only when the standard deviation of MFAZ is rated as not problematic. If
#' Calculate the prevalence estimates of wasting based on z-scores of
#' MUAC-for-age and/or bilateral edema. The function allows users to estimate
#' prevalence in accordance with complex sample design properties such as
#' accounting for survey sample weights when needed or applicable. The quality
#' of the data is first evaluated by calculating and rating the standard
#' deviation of MFAZ. Standard approach to prevalence estimation is calculated
#' only when the standard deviation of MFAZ is rated as not problematic. If
#' the standard deviation is problematic, prevalence is estimated using the
#' PROBIT estimator. Outliers are detected based on SMART flagging criteria.
#' Identified outliers are then excluded before prevalence estimation is
#' PROBIT estimator. Outliers are detected based on SMART flagging criteria.
#' Identified outliers are then excluded before prevalence estimation is
#' performed.
#'
#' @param df A `data.frame` object that has been produced by the
#' [mw_wrangle_age()] and [mw_wrangle_muac()] functions. The `df` should have a
#' variable named `cluster` for the primary sampling unit identifiers.
#'
#' @param wt A vector of class `double` of the survey sampling weights. Default
#' is NULL which assumes a self-weighted survey as is the case for a survey
#' @param wt A vector of class `double` of the survey sampling weights. Default
#' is NULL which assumes a self-weighted survey as is the case for a survey
#' sample selected proportional to population size (i.e., SMART survey sample).
#' Otherwise, a weighted analysis is implemented.
#'
#' @param edema A `character` vector for presence of nutritional edema coded as
#' "y" for presence of nutritional edema and "n" for absence of nutritional
#' "y" for presence of nutritional edema and "n" for absence of nutritional
#' edema. Default is NULL.
#'
#' @param .by A `character` or `numeric` vector of the geographical areas
Expand Down
Loading
Loading