undo_pr | R Documentation |
Make a new vital from products and ratios of a measured variable by a key variable. The most common use case of this function is for computing mortality rates by sex, from the sex ratios and geometric mean of the rates.
undo_pr(.data, .var, key = Sex, times = 2000)
.data |
A vital object |
.var |
A bare variable name of the measured variable to use. |
key |
A bare variable name specifying the key variable to use. This key
variable must include the value |
times |
When the variable is a distribution, the product must be computed by simulation. This argument specifies the number of simulations to use. |
Note that when a measured variable takes value 0, the geometric mean is set to 10^-6 to avoid infinite values in the ratio. Therefore, when the transformation is undone, the results will not be identical to the original in the case that the original data was 0.
A vital object
Hyndman, R.J., Booth, H., & Yasmeen, F. (2013). Coherent mortality forecasting: the product-ratio method with functional time series models. Demography, 50(1), 261-283.
# Make products and ratios
orig_data <- aus_mortality |>
dplyr::filter(Year > 2015, Sex != "total", Code == "NSW")
pr <- orig_data |>
make_pr(Mortality)
# Compare original data with product/ratio version
orig_data
pr
# Undo products and ratios
pr |> undo_pr(Mortality)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.