compare_estimate | R Documentation |
Compare aggregated results (proportions or means) for one strata to the rest of the strata in the summary table.
compare_estimate(
mydt,
id_vars = c("variable", "level"),
key_where,
new_col = "comp",
tidy = T
)
mydt |
Unquoted name of a data.table or data.frame to be processed. Note the table must have the following columns: 'result' OR 'mean' OR 'proportion', and corresponding confidence interval columns with 'lower' & 'upper' as part of their names. |
id_vars |
Character vector of length >= 1. It contains the name(s) of columns which identify the grouping for which you want to use for comparison. For standard rads::calc() output, id_vars should be c("variable", "level") and for standard CHI tableau ready output, it should be c("indicator_key", "year") |
key_where |
An expression identifying the referent/comparator/key to which other data will be compared. It should be passed unquoted. rows to be filtered / excluded from secondary suppression because the categories are not mutually exclusive (e.g., race3) |
new_col |
Character vector of length 1. It is the name of the new column that contains the comparison results (i.e., higher, lower, or no difference). It is also the stem for the column noting the significance of the results ( e.g., if new_col = "comp", the significance column will be named "comp_sig") |
tidy |
logical. Determines whether to drop intermediate variables with the estimate, lower bound, and upper bound for the referent. |
data.table comprised of the original data.table and two additional columns ... 'comp' and 'comp_sig' (or alternatively specified names)
# create test data
set.seed(98104)
dt <- data.table::data.table(
chi_year = rep(2008:2018, 2000),
fetal_pres = factor(sample(c("Breech", "Cephalic", "Other", NA),
22000, rep = TRUE,
prob = c(0.04, 0.945, 0.01, 0.005))),
bw_grams = round(rnorm(22000, 3343, 576), 0)
)
dt[fetal_pres=='Other', bw_grams := 0.5*bw_grams]
dt = dtsurvey::dtadmin(dt)
dt <- calc(dt, what = c("bw_grams"), by = c("fetal_pres"))
# run function
test <- compare_estimate(mydt = dt,
id_vars = c("variable", "level"),
key_where = fetal_pres == "Breech",
new_col = "comp",
tidy = FALSE)
test[]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.