---
title: "Checking if IPC Acute Malnutrition sample size requirements were met"
author: Tomás Zaba
bibliography: references.bib
csl: harvard-cite-them-right-11th-edition.csl
knitr:
  opts_chunk: 
    collapse: true
    comment: "#>"
vignette: >
  %\VignetteIndexEntry{Checking if IPC Acute Malnutrition sample size requirements were met}
  %\VignetteEngine{quarto::html}
  %\VignetteEncoding{UTF-8}
---

```{r}
#| label: global-setup
#| echo: false
#| message: false

library(mwana)
```


Evidence on the prevalence of acute malnutrition used in the IPC Acute Malnutrition (IPC AMN) can come from different sources: representative surveys, screenings, or community-based surveillance system (known as sentinel sites). The IPC sets minimum sample size requirements for each of these sources [@ipcmanual].

In the IPC AMN analysis workflow, the first step a data analyst has to take is the checking of sample size requirements as set by IPC for each survey area to be included in the IPC AMN analysis. `mwana` provides the `mw_check_ipcamn_ssreq()` function for this purpose.

To demonstrate its usage, we will use the built-in sample dataset `anthro.01`.

```{r}
#| label: view-data
#| echo: true

head(anthro.01)
```


`anthro.01` contains anthropometry data from SMART surveys from anonymized locations. To learn more about this dataset, call `help("anthro.01")` in your `R` console. 

Now that we got acquainted with the dataset, we can proceed to executing the task. The function takes three arguments: `df`, the dataset you want to assess sample sizes for (`anthro.01` in this case); `cluster`, the unquoted variable name in `df` that contains information for the unique cluster or screening or sentinel site identifiers (`anthro.01` has a variable called `cluster` which we supply here unquoted); and `.source`, the type of source for the data in `df` (since `anthro.01` data is from a survey, we specify this argument as *"survey"*). To achieve this, we simply do:


```{r}
#| label: check
#| echo: true
#| eval: false

mw_check_ipcamn_ssreq(
  df = anthro.01,
  cluster = cluster,
  .source = "survey"
)
```

We can also chain `anthro.01` to the function using the native pipe operator `|>`:


```{r}
#| label: pipe_operator
#| echo: true
#| eval: false

anthro.01 |>
  mw_check_ipcamn_ssreq(
    cluster = cluster,
    .source = "survey"
  )
```

Either way, the returned output will be: 

```{r}
#| label: view_check
#| echo: false

anthro.01 |>
  mw_check_ipcamn_ssreq(
    cluster = cluster,
    .source = "survey"
  )
```

A `tibble` object is returned with three columns:  

  + `n_clusters` counts the number of unique cluster or villages or community identifiers in the dataset where the data collection took place.
  
  + `n_obs` counts the number of children from which data were collected.
  
  + `meet_ipc` indicates whether the IPC AMN sample size requirements (for surveys in this case) were met or not.

The above output is not quite useful yet as we often deal with multiple-area datasets. We can get a summarized output by area as follows, by supplying `area`—a vector containing the categories for which the analysis should be summarised (more than one vector can be specified, separated by `,`):


```{r}
#| label: group_by
#| echo: true
#| eval: false

anthro.01 |>
  mw_check_ipcamn_ssreq(
    cluster = cluster,
    .source = "survey",
    area
  )
```

This will return: 

```{r}
#| label: view_group_by
#| echo: false

anthro.01 |>
  mw_check_ipcamn_ssreq(
    cluster = cluster,
    .source = "survey",
    area
  )
```

For screening or sentinel site-based data, we approach the task the same way; we only have to change the `.source` parameter to "screening" or to "ssite" as appropriate, as well as to supply `cluster` with the right column name of the sub-areas inside the main area (villages, localities, comunas, communities, etc).

# References
