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)

Table of Contents

  1. Introduction
  2. Run models
  3. Post-process
  4. Plot model results

Introduction

This package is the one country implementation of FPEM. It uses higher level parameters estimated in FPEMglobal. The package can be installed by cloning and using devtools::install(). The source code for vignettes can be found in /vignettes. The directory /design contains technical details about the design of this project for package maintainers and contributors. Below is a brief introduction.

knitr::opts_chunk$set(echo = TRUE)
library(FPEMlocal)
library(ggplot2)
library(grid)
library(gridExtra)
devtools::load_all()

Run models

fpem_one_country is a generic wrapper function to run the family planning estimation model for a country of interest. The wrapper functions ending in _autosave such as fpem_one_country_autosave save the output and name the files using the runname argument. We will use the division code for Bolivia here as the runname.

When a survey file is not provided (as in this example) the function uses default data from contraceptive_use. The user may also supply optional services statistics. See ??service_stats for required service statistic data format. See ??do_1country_run for all possible inputs to this wrapper function. If you wish to obtain results for all women posterior_samples_all_women can be used after completing a run for married women and a run for unmarried women. See FPEM/vignettes for more details

div <- 68
fpem_one_country_autosave(
  runname = paste0(div),
  is_in_union = "Y",
  service_stats = FALSE,
  division_numeric_code = div,
  first_year = 1970,
  last_year = 2030,
  diagnostic = TRUE,
  params_to_save = c(
    "mod.ct",
    "unmet.ct",
    "trad.ct",
    "mu.in",
    "logitratio.yunmet.hat.i",
    "pmax.c",
    "logitpmax.c",
    "logitRmax.c",
    "Rmax.c",
    "logitomega.c",
    "omega.c",
    "Romega.c",
    "logitRomega.c",
    "s.ct",
    "setlevel.c",
    "P.ct",
    "RT.c",
    "unmet.intercept.c"
  ),
  nchains = 6,
  niter = 10000,
  nburnin = 1000
)

Process the samples

fpem_get_results returns point-estimates for several indicators in long-format.

fpem_results_autosave(
  runname = paste0(div)
)

Plot the results

fpem_get_plots plots the results of the model againts the observations. Choose any indicators returned from fpem_calculate_results

indicators <- c(
    "unmet_need_any",
    "contraceptive_use_modern",
    "contraceptive_use_traditional",
    "contraceptive_use_any"
    )

fpem_plot_autosave(
  runname = paste0(div),
  indicators = indicators,
  compare_to_global = TRUE
  )


# gridExtra::grid.arrange(grobs=plots[1:length(indicators)],
#                  ncol=2,
#                  top="In-union women")


FPRgroup/FPEMcountry documentation built on April 24, 2023, 4:32 p.m.