knitr::opts_chunk$set(echo = TRUE) knitr::opts_knit$set(root.dir = rprojroot::find_rstudio_root_file()) # knitr::opts_knit$get("root.dir") # alternative to the previous line # the default autosave location will depend on this being setup options(warn=-1)
library(fpemlocal)
In this vignette we obtain estimates for married women with custom user data.
fit_fp_c
calc_fp_c
plot_fp_c
Fit the one-country family planning estimation model with the function fit_fp_c
. Supply the file path of the .csv file containing your country survey data to the argument surveydata_filepath
. Next supply the UNPD country code known as the division_numeric_code
. See ??divisions
for UNPD country codes and other divisions. Specify the model of your choice with the argument is_in_union
. There are two versions of this model, one for in-union women and another for not-in-union women denoted "Y"
and "N"
respectively. Lastly, specify the years of estimates to be returned. Note: The function will not filter the survey data based on these years. All years of available survey data will be used.
fit <- fit_fp_c( surveydata_filepath = "data-raw/manuscript_example_data/afghanistan_4_married_example.csv", 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
to the argument fit
. Read in your population count dataset. Then supply the dataset to the argument population_data
.
population_data <- read.csv("data-raw/manuscript_example_data/afghanistan_4_married_popdata_example.csv") results <- calc_fp_c(fit = fit, population_data = population_data)
A set of results here consist of the following family planning indicators
results$Y %>% names
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.