Unlimited learning, half price | 50% off

Last chance! 50% off unlimited learning

Sale ends in


AgePopDenom

What is AgePopDenom?

AgePopDenom is an R package designed to facilitate the generation of fine-scale, age-structured population denominators for public health decision-making and service delivery. By combining census and household survey data with a novel parameter-based geostatistical modeling approach, the package produces high-resolution (5km x 5km) population estimates disaggregated by age.


Installation

System Requirements

Before installing AgePopDenom, ensure your system meets the following requirements:

  1. R version: >= 4.1.0
  2. C++ compiler: C++17 compatible
  3. TMB (Template Model Builder)

Platform-Specific Setup

Windows

  1. Install Rtools (matches your R version):
# Check if Rtools is installed and properly configured
pkgbuild::has_build_tools()

If FALSE, download and install Rtools from: CRAN Rtools

  1. After installation, add Rtools to the system PATH:
echo 'export PATH="C:/rtools43/usr/bin;C:/rtools43/mingw64/bin:$PATH"' >> ~/.Renviron
  1. Restart R and verify the correct compiler setup:
Sys.getenv("PATH")

It should include C:/rtools43/usr/bin and C:/rtools43/mingw64/bin.

  1. Ensure the correct compiler is available:
g++ --version

It should output GCC version 10 or later.

  1. Set up the Makevars.win file to use the correct compiler:
mkdir -p ~/.R
nano ~/.R/Makevars.win

Add the following lines:

CXX14=C:/rtools43/mingw64/bin/g++
CXX17=C:/rtools43/mingw64/bin/g++
CXX20=C:/rtools43/mingw64/bin/g++

Save and exit (CTRL+X, then Y, then Enter).

macOS

  1. Install Command Line Tools:
xcode-select --install
  1. Alternatively, install gcc via Homebrew:
brew install gcc
  1. Install LLVM via Homebrew:
brew install llvm
  1. Set up compiler paths:

For Zsh (default on macOS):

echo 'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"' >> ~/.zshrc
echo 'export LDFLAGS="-L/opt/homebrew/opt/llvm/lib"' >> ~/.zshrc
echo 'export CPPFLAGS="-I/opt/homebrew/opt/llvm/include"' >> ~/.zshrc
source ~/.zshrc

For Bash:

echo 'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"' >> ~/.bashrc
echo 'export LDFLAGS="-L/opt/homebrew/opt/llvm/lib"' >> ~/.bashrc
echo 'export CPPFLAGS="-I/opt/homebrew/opt/llvm/include"' >> ~/.bashrc
source ~/.bashrc
  1. Verify the correct compiler is now being used:
clang++ --version

It should output Homebrew Clang (e.g., Homebrew clang version XXXXX).

  1. Configure R to use LLVM: Modify your ~/.R/Makevars file:

nano ~/.R/Makevars

Add the following lines:

CXX=/opt/homebrew/opt/llvm/bin/clang++
CXX11=/opt/homebrew/opt/llvm/bin/clang++
CXX14=/opt/homebrew/opt/llvm/bin/clang++
CXX17=/opt/homebrew/opt/llvm/bin/clang++
CXX20=/opt/homebrew/opt/llvm/bin/clang++

Save and exit (CTRL+X, then Y, then Enter).

Linux (Ubuntu/Debian)

  1. Update your system and install necessary packages:
sudo apt-get update
sudo apt-get install build-essential libxml2-dev
  1. Ensure you have GCC installed:
sudo apt-get install g++
  1. Install Clang (optional, if required for TMB compilation):
sudo apt-get install clang
  1. Verify compiler setup:
g++ --version
clang++ --version

Install and Compile TMB

Restart R and install TMB:

install.packages("TMB", type = "source")

AgePopDenom installation

Once the setup is complete, follow the instructions below to download AgePopDenom

Note: AgePopDenom is currently under development. Once it is available on CRAN, you will be able to install it using the following command:

# install.packages("AgePopDenom")

To get the development version from GitHub, use:

# install.packages("devtools")
devtools::install_github("truenomad/AgePopDenom")

Then load it in R:

library(AgePopDenom)

Core Functions

  1. Initialize project structure:
init()
  1. Download required data:
# Example for Kenya and Uganda
countries <- c("KEN", "UGA")

# Get DHS data
download_dhs_datasets(countries, 
                      email = "my_email@example.com",
                      project = "Population denominator project")

# Process DHS data
process_dhs_data()

# Download shapefiles
download_shapefile(countries)

# Download population rasters from worldpop
download_pop_rasters(countries)

# Extract urban extent raster
extract_afurextent()
  1. Run full analysis:
run_full_workflow(countries)

Documentation

For detailed documentation and examples, visit our package website.

Support and Contributions

For support, bug reports, or feature requests, please contact:

  • Mo Yusuf (Package Developer)
    Email: moyusuf@who.int
    Affiliation: World Health Organization Regional Office for Africa, P.O. Box 06, Cite du Djoue, Brazzaville, Congo

Alternatively, open an issue on the GitHub repository.

We welcome contributions from the community to improve AgePopDenom.

Copy Link

Version

Install

install.packages('AgePopDenom')

Monthly Downloads

230

Version

0.4.0

License

MIT + file LICENSE

Maintainer

Mohamed A. Yusuf

Last Published

February 25th, 2025

Functions in AgePopDenom (0.4.0)

create_project_structure

Create a Standardized Project Folder Structure
generate_age_pop_raster

Generate Age Population Raster
init

Initialize Full Pipeline Script and Model Script
generate_gamma_raster_plot

Generate and Save Raster Plot for Gamma Predictions
fit_spatial_model

Fit a Spatial Model for Age Parameters using TMB
generate_age_pop_table

Generate Age Population Tables
generate_variogram_plot

Generate Variogram Plot
generate_gamma_predictions

Predict Gamma Distribution Parameters for Spatial Grid
generate_age_pyramid_plot

Generate and Save Age Pyramid Plot
install_suggested_packages

Package Initialization and Dependency Check
process_dhs_data

Process DHS Data: Merge RDS Files with Shapefiles and Extract Gamma Parameters
log_lik

Log-Likelihood Function for Spatial Model
process_gamma_predictions

Process Gamma Prediction Results
run_full_workflow

Run Country-Specific Spatial Modeling Workflow with Logging
process_final_population_data

Process Final Population Data
rasterize_data

Rasterize Spatial Data
create_prediction_data

Generate or Load Cached Predictors Data
compute_cov

Compute Covariance Matrix for Spatial Model
download_shapefile

Download WHO ADM2 Boundaries with Partial Update
download_dhs_datasets

Main Function to Download DHS Datasets
extract_betas

Extract Beta Parameters from Model Output
download_pop_rasters

Download population rasters for given country codes.
extract_age_param

Extract Parameters and Optimization Details with Log-Likelihood
aggregate_and_extract_gamma

Aggregate Individual Survey Data and Extract Gamma Parameters by Location
extract_afurextent

Extract Urban/Rural Extent Raster