summarize_lt | R Documentation |
Calculate summary statistics for life tables when collapsing over a certain variable. For example can calculate summary statistics across a set of draws, or locations, or location-years, etc.
summarize_lt(
dt,
id_cols,
summarize_cols,
value_cols,
summary_fun = c("mean"),
probs = c(0.025, 0.975),
recalculate_starting_params = c("mx", "ax"),
recalculate_stats = c("mean"),
preserve_u5 = FALSE,
assert_na = FALSE,
format_long = FALSE
)
dt |
[ |
id_cols |
[ |
summarize_cols |
[ |
value_cols |
[ |
summary_fun |
[ |
probs |
[ |
recalculate_starting_params |
[ |
recalculate_stats |
[ |
preserve_u5 |
[ |
assert_na |
[ |
format_long |
[ |
One example use case for summarize_lt
is when we have multiple draws
(independent simulations) of life tables to propagate uncertainty. Each of
the independent draws of life tables may have all life table parameters. The
mean, 2.5th and 97.5 percentiles across all draws for all life table
parameters can be calculated. But the mean 'mx', 'qx', 'ax' parameters would
be inconsistent with the mean 'ex' parameter for example. This is when
specifying recalculate_stats = 'mean'
would recalculate the mean 'ex'
parameter using the mean 'mx', 'qx', and/or 'ax' as inputs to the
demCore::lifetable
function.
[data.table()
] with id_cols
(minus the summarize_cols
) plus
summary statistic columns. The summary statistic columns have the same name
as each function specified in summary_fun
and the quantiles are named
like 'q_(probs * 100)
'. Each of the summary statistic columns that are
returned are prefixed with the value column name. If format_long
then
output is returned with a 'life_table_parameter' column and a column for
each summary statistic.
demUtils::summarize_dt
demCore::lifetable
demCore::validate_lifetable
library(data.table)
data("austria_1992_lt")
dt <- data.table::data.table()
for(d in 1:100){
dt_new <- copy(austria_1992_lt)
dt_new[, draw := d]
dt_new[, mx := mx * rnorm(1, mean = 1, sd = 0.05)]
dt_new[, ax := ax * rnorm(1, mean = 1, sd = 0.05)]
dt_new[, qx := NULL]
dt <- rbind(dt, dt_new, fill = TRUE)
}
dt <- dt[!is.na(age_start)]
dt <- dt[, .(age_start, age_end, draw, mx, ax)]
dt <- summarize_lt(
dt = dt,
id_cols = c("age_start", "age_end", "draw"),
summarize_cols = c("draw"),
value_cols = c("mx", "ax"),
recalculate_stats = "mean"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.