knitr::opts_chunk$set(echo = TRUE) knitr::opts_knit$set(root.dir = rprojroot::find_rstudio_root_file()) options(warn=-1)
library(fpemlocal)
In this vignette we obtain estimates for married women with package datasets. By default, functions utilize UNPD datasets.
fit_fp_c
calc_fp_c
plot_fp_c
First, find the UNPD country code under the variable division_numeric_code
in the dataset divisions
. See ?divisions
for the metadata.
divisions %>% dplyr::filter(name_country == "Afghanistan")
Fit the one-country family planning estimation model with the function fit_fp_c
. First, supply the UNPD country code to the argument division_numeric_code
. There are two versions of this model, one for in-union women and another for not-in-union women denoted "Y"
and "N"
respectively. Specify the model of your choice with the argument is_in_union
. By default, the function fit_fp_c
utilizes the UNPD contraceptive use survey dataset, contraceptive_use
and filters the dataset based on the aforementioned function arguments. Lastly, specify the years of estimates to be returned. Note: year arguments will not filter the supplied survey data. All years of available survey data will be used.
fit <- fit_fp_c( division_numeric_code = 4, is_in_union = "Y", first_year = 1970, last_year = 2030 )
Calculate point estimates for family planning indicators with the function calc_fp_c
. Supply the fit object from fit_fp_c
. By default, the function calc_fp_C
utilizes the UNPD population dataset, population_counts
to calculate count variables such as the number of women using modern contraceptives.
results <- calc_fp_c(fit)
A set of results here consist of the following family planning indicators
results$Y %>% names
results$Y
The point estimates for each indicator are long-format tibbles. Let's take a look at the tibble for the indicator contraceptive_use_modern
results$Y$contraceptive_use_modern
fpemlocal also includes a function named plot_fp_c
to plot the calculated point estimates against the survey data. The arguments to this function are, the fit object from step 1, the results from step 2, and a vector of indicator names. The vector of indicator names corresponds to the names which appear in the results from step 2.
plot_fp_c( fit, results, indicators = c( "unmet_need_any", "contraceptive_use_modern", "contraceptive_use_traditional", "contraceptive_use_any" ) )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.