Skip to content

About

Code and aggregated data for Bayesian estimation of UK migrant age-sex profiles using LFS and Facebook data, with Census 2021 validation.

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Migrant Age Profiles from Digital Trace and Survey Data

Overview of the migrant-stock modelling framework

R JAGS License: MIT Article status

Code and replication materials for:

Rampazzo, F., Bijak, J., Vitali, A., Weber, I. and Zagheni, E. (2026). “Migrant Age Profiles Reconciling Digital Trace and Survey Data: An Example of the United Kingdom in 2018 and 2019.” Journal of the Royal Statistical Society Series A: Statistics in Society. https://doi.org/10.1093/jrsssa/qnag090

This repository extends the framework in Rampazzo et al. (2021) by estimating migrant-stock profiles jointly by age and sex. It combines UK Labour Force Survey estimates with aggregate audience estimates from the Facebook Advertising Platform in a Bayesian multinomial–Dirichlet–Dirichlet model.

Abstract

Accurate estimates of migrant population stocks by age and sex are important for demographic analysis and policy. This study develops a hierarchical Bayesian model that integrates Labour Force Survey data with digital trace data from the Facebook Advertising Platform. Reduced Rogers–Castro schedules provide first-stage smoothing, and a multinomial–Dirichlet–Dirichlet hierarchy reconciles the source-specific profiles. The application covers the ten largest European migrant groups in the United Kingdom in 2018 and 2019 and validates the estimated profiles against Census 2021 country-of-birth data for England and Wales.

Repository structure

Path Contents
Data/public/ Publication-safe Facebook totals and age/sex proportions
Data/census 2021/ Census 2021 comparison inputs
model.R Main data preparation and model-fitting workflow
model_mdd.txt Main JAGS multinomial–Dirichlet–Dirichlet model
run_mdd_diagnostic_sample.R Refit used for convergence diagnostics
diagnose_mdd_convergence.R Convergence summaries and selected trace plots
gof/ Posterior predictive checks and Rogers–Castro diagnostics
census_comparison/ External validation against Census 2021 profiles
arek_model_sensitivity/ Age–sex sensitivity specification and comparisons
bayesian_rc/ Alternative Rogers–Castro sensitivity models
paper/ Manuscript, supplement, bibliography, tables, figures, and build sources

Restricted Facebook source inputs, large posterior sample objects (*.RData), and local build products are intentionally excluded from Git. The public Facebook files contain only aggregate totals and proportions.

Requirements

  • R (developed with R 4.x)
  • JAGS
  • R packages: coda, dplyr, knitr, MCMCvis, readr, readxl, rjags, runjags, scales, stringr, tidyr, tidyverse, and xtable
  • For rebuilding the manuscript: rmarkdown and kableExtra

Install JAGS before installing rjags or runjags. From R, the core packages can be installed with:

install.packages(c(
  "coda", "dplyr", "knitr", "kableExtra", "MCMCvis", "readr",
  "readxl", "rjags", "rmarkdown", "runjags", "scales", "stringr",
  "tidyr", "tidyverse", "xtable"
))

Reproducing the analysis

Run commands from the repository root because the scripts use project-relative paths.

The complete model fit requires the restricted third-party source inputs used by the authors. These files are not distributed through GitHub. The public repository provides the analysis code, model specifications, derived Facebook totals and proportions, diagnostics, and reported outputs. Researchers with authorised access can place the restricted inputs at the paths documented in the scripts.

  1. Fit the main model:

    source("model.R")
  2. Generate a diagnostic posterior sample and convergence summaries:

    source("run_mdd_diagnostic_sample.R")
    source("diagnose_mdd_convergence.R")
  3. Run posterior predictive and Rogers–Castro checks using the scripts in gof/.

  4. Run the external Census comparison:

    source("census_comparison/compare_census_profiles.R")
  5. Rebuild manuscript figures and documents using the scripts and R Markdown sources in paper/.

The Bayesian models are computationally intensive. Runtime depends on the number of chains, iterations, and available cores. The scripts set their own sampling configurations; review these before running on a shared system.

Data availability

The public Facebook-derived files contain only totals by country, year, and sex and age-group proportions within those strata. Raw Facebook exports and age-specific audience counts are not published. Source data obtained from third-party providers, including the Labour Force Survey and the Facebook Advertising Platform, remain subject to the access conditions and terms of use of the original providers. Census comparison data originate from the Office for National Statistics.

Citation

Please cite the accepted article using the citation above. Machine-readable metadata are provided in CITATION.cff. The citation will be updated with volume, pages, and DOI after publication.

For the earlier total-stock framework, cite:

Rampazzo, F., Bijak, J., Vitali, A., Weber, I. and Zagheni, E. (2021). “A Framework for Estimating Migrant Stocks Using Digital Traces and Survey Data: An Application in the United Kingdom.” Demography, 58(6), 2193–2218. https://doi.org/10.1215/00703370-9578562

Authors

License

The analysis code is released under the MIT License. This license does not override third-party rights or access conditions attached to the input data.

About

Code and aggregated data for Bayesian estimation of UK migrant age-sex profiles using LFS and Facebook data, with Census 2021 validation.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages