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.
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.
| 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.
- R (developed with R 4.x)
- JAGS
- R packages:
coda,dplyr,knitr,MCMCvis,readr,readxl,rjags,runjags,scales,stringr,tidyr,tidyverse, andxtable - For rebuilding the manuscript:
rmarkdownandkableExtra
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"
))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.
-
Fit the main model:
source("model.R") -
Generate a diagnostic posterior sample and convergence summaries:
source("run_mdd_diagnostic_sample.R") source("diagnose_mdd_convergence.R")
-
Run posterior predictive and Rogers–Castro checks using the scripts in
gof/. -
Run the external Census comparison:
source("census_comparison/compare_census_profiles.R") -
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.
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.
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
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.
