
Test many reported percentages against their counts
Source:R/percentage-of-map.R
percentage_of_map.Rdpercentage_of_map() applies percentage_of() to
every row of a data frame with counts, percentages, and totals.
Call audit() on the output for summary statistics. See
percentage_of() for causes of inconsistencies.
Usage
percentage_of_map(
data,
digits_percentage,
absolute = NULL,
percentage = NULL,
n = NULL,
...,
rounding = "up_or_down",
threshold = 5,
symmetric = FALSE
)Arguments
- data
Data frame with columns
absolute,percentage, andn. Any other columns are returned alongside the results.- digits_percentage
Integer. The number of decimal places in
percentage, including trailing zeros. There is no default, since a numeric value does not keep them (1.40is1.4). Either a single number for the whole column or one number per row ofdata. If left out, it is taken from adigits_percentagecolumn ofdata.- absolute, percentage, n
Optionally, the names of the columns in
datathat contain these values, if they differ from the defaults.- ...
These dots must be empty. Every argument after them must be named in full.
- rounding, threshold, symmetric
The same as in
grim().
Value
A tibble with the columns absolute, percentage, n,
digits_percentage, consistency, and any other columns from data. It
has the class scrutiny_percentage_of_map, which is recognized by
audit().
Summaries with audit()
audit() on percentage_of_map() output
returns a tibble with one row and these columns:
all_cases: total number of value sets.incon_cases: number of inconsistent value sets.emp_incon: proportion of inconsistent value sets.
Examples
df <- tibble::tibble(
absolute = c(40, 37, 25),
percentage = c(33, 31, 20),
n = 120
)
df |>
percentage_of_map(digits_percentage = 0)
#> # A tibble: 3 × 5
#> # Percentage: default settings
#> absolute percentage n digits_percentage consistency
#> <int> <dbl> <int> <int> <lgl>
#> 1 40 33 120 0 TRUE
#> 2 37 31 120 0 TRUE
#> 3 25 20 120 0 FALSE