tab_linelist | R Documentation |
Tabulate counts and proportions
tab_linelist(
x,
...,
strata = NULL,
keep = TRUE,
drop = NULL,
na.rm = TRUE,
prop_total = FALSE,
row_total = FALSE,
col_total = FALSE,
wide = TRUE,
transpose = NULL,
digits = 1,
pretty = TRUE
)
tab_survey(
x,
...,
strata = NULL,
keep = TRUE,
drop = NULL,
na.rm = TRUE,
prop_total = FALSE,
row_total = FALSE,
col_total = FALSE,
wide = TRUE,
transpose = NULL,
digits = 1,
method = "logit",
deff = FALSE,
pretty = TRUE
)
x |
a |
... |
categorical variables to tabulate |
strata |
a stratifier to split the data |
keep |
a character vector specifying which values to retain in the
tabulation. Defaults to |
drop |
a character vector specifying which values to drop in the
tabulation. Defaults to |
na.rm |
When |
prop_total |
if |
row_total |
create a new column with the total counts for each row of stratified data. |
col_total |
create a new row with the total counts for each column of stratified data. |
wide |
if |
transpose |
if
|
digits |
(survey only) if |
pretty |
(survey only) if |
method |
(survey only) a method from |
deff |
a logical indicating if the design effect should be reported.
Defaults to |
a tibble::tibble()
with a column for variables, a column for values,
and counts and proportions. If strata
is not NULL
and wide = TRUE
,
then there will be separate columns for each strata for the counts and
proportions. Survey data will report confidence intervals.
have_packages <- require("matchmaker") & require("epidict")
if (have_packages) {
withAutoprint({
# Simulating linelist data
linelist <- epidict::gen_data("Measles", numcases = 1000, org = "MSF")
measles_dict <- epidict::msf_dict("Measles", compact = FALSE)
# Cleaning linelist data
linelist_clean <- matchmaker::match_df(
x = linelist,
dictionary = measles_dict,
from = "option_code",
to = "option_name",
by = "data_element_shortname",
order = "option_order_in_set"
)
# get a descriptive table by sex
tab_linelist(linelist_clean, sex)
# describe prenancy statistics, but remove missing data from the tally
tab_linelist(linelist_clean, trimester, na.rm = TRUE)
# describe by symptom
tab_linelist(linelist_clean,
cough, nasal_discharge, severe_oral_lesions,
transpose = "value"
)
# describe prenancy statistics, stratifying by vitamin A perscription
tab_linelist(linelist_clean, trimester, sex,
strata = prescribed_vitamin_a,
na.rm = TRUE, row_total = TRUE
)
})
}
have_survey_packages <- require("survey") && require("srvyr")
if (have_survey_packages) {
withAutoprint({
data(api)
# stratified sample
surv <- apistrat %>%
as_survey_design(strata = stype, weights = pw)
s <- surv %>%
tab_survey(awards, strata = stype, col_total = TRUE, row_total = TRUE, deff = TRUE)
s
# making things pretty
s %>%
# wrap all "n" variables in braces (note space before n).
epikit::augment_redundant(" (n)" = " n") %>%
# relabel all columns containing "prop" to "% (95% CI)"
epikit::rename_redundant(
"% (95% CI)" = ci,
"Design Effect" = deff
)
# long data
surv %>%
tab_survey(awards, strata = stype, wide = FALSE)
# tabulate binary variables
surv %>%
tab_survey(yr.rnd, sch.wide, awards, keep = "Yes")
# stratify the binary variables
surv %>%
tab_survey(yr.rnd, sch.wide, awards,
strata = stype,
keep = "Yes"
)
# invert the tabulation
surv %>%
tab_survey(yr.rnd, sch.wide, awards,
strata = stype,
drop = "Yes",
deff = TRUE,
row_total = TRUE
)
})
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.