This repository contains the code base used for the analysis in Social Media Data for Population Mapping: A Bayesian Approach to Address Representativeness and Privacy Challenges.
All the openly available data required to replicate the analysis is collected for ease of use in this data repository. Information on requesting access to the Meta datasets can be found here.
To run the notebooks the data folder needs to be added to the repo and the Meta datasets should be included in the data\raw folder as FB_daily_8hr_pop_tiles_2020.csv and FB_daily_8hr_pop_tiles_2021.csv for the 2020 and 2021 tile level data respectively.
The analysis is split in a series of notebooks that cover different parts of the data preparation, modelling and visualisation steps (as described below).
The modelling code can be tested even without access to the Meta datasets as sections of the relative notebooks are dedicated to generating synthetic data for this purpose.
The notebooks make use of functions and models defined in the files contained in the src and model folders respectively.
The code was created using R version 4.5.2 and was tested using RStudio version 2025.09.2+418. renv version 1.1.5 was used to manage package dependencies. The instructions that follow describe how to replicate the analysis using the RStudio IDE.
- Open the project file
meta-pop-philippines.Rprojin RStudio. - In the console activate the project environment
renv::init() - Select 1 to restore the environment from the existing lock file.
Running the notebooks in the order described below ensures that the processed datasets required for the modelling steps are appropriately created (note that it is not required to run the 0_fb_data_exploration.qmd)
| Name | Description | Notes |
|---|---|---|
| 0_fb_data_exploration.qmd | Provides a brief exploratory analysis of the Facebook data | Creates a folder images in the repo where all generated images are stored. |
| 1_fb_data_impotation.qmd | Notebook dedicated to the imputation of the Facebook missing data by modelling the censoring process | Both a hierarchical and a non-hierarchical approaches are presented. The results in the manuscript mostly refers to the former. It creates a model_outputs folder where outputs of the models and intermediary data needed for visualisations are stored. If not existing, it also creates the image folder. |
| 2_prepare_ookla_data.qmd | Collects data from the Ookla API, cleans it and provides some visualisations. | This data is not used in the modelling phase so this notebook can be skipped but references to the relative columns need to be removed accordingly in the other notebooks. |
| 3_data_processing.qmd | Processes and harmonises all the datasets. | |
| 4_fb_data_processing_comparison.qmd | Compares the impact on the final Facebook data of different preprocessing approaches | It is not necessary to run this notebook to be able to run the models. |
| 5_data_visualization.qmd | Explores the final harmonised dataset through a series of visualisations | It is not necessary to run this notebook to be able to run the models. |
| 6_data_modelling.qmd | Runs the Facebook user proportion models | |
| 7_create_figures_for_manuscript.qmd | Generates all the figures presented in the manuscript |