knitr::opts_chunk$set(echo = TRUE)
knitr::opts_knit$set(root.dir = rprojroot::find_rstudio_root_file())
options(warn=-1)
knitr::opts_chunk$set(echo = TRUE)
library(fpemlocal)
devtools::load_all()

Introduction

In this vignette we will fit FPET to multiple countries and aggregate the samples to obtain results for aggregate levels. We will fit models for Botswana and Lesotho, country codes 72 and 426 respectively.

Table of Contents

  1. Fit models
  2. Read in population data4
  3. Calculate results

Fit models

First, fit the models with the function fit_fp_c.

fit_botswana <- fit_fp_c(
  surveydata_filepath = "data-raw/manuscript_example_data/Botswana_72_married_example.csv",
  division_numeric_code = 72,
  is_in_union = "Y",
  first_year = 1970,
  last_year = 2030
)
fit_lesotho <- fit_fp_c(
  surveydata_filepath = "data-raw/manuscript_example_data/Lesotho_426_married_example.csv",
  division_numeric_code = 426,
  is_in_union = "Y",
  first_year = 1970,
  last_year = 2030
)

Read in population data

Read in population data for the populations of interest. Create a single dataset with the function rbind.

popdata_botswana <- read.csv("data-raw/manuscript_example_data/Botswana_72_married_popdata_example.csv")
popdata_lesotho <- read.csv("data-raw/manuscript_example_data/Lesotho_426_married_popdata_example.csv")
popdata <- rbind(popdata_botswana, popdata_lesotho)

Calculate results

Supply the fits in a list and the population data to the function calc_fp_aggregate. The resulting object is a list of long format tibbles with family planning estimates.

results <- calc_fp_aggregate(fits = list(fit_botswana, fit_lesotho),
                   population_data = popdata)
results %>% head()


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