Variation in smallholder farm size across Sub Saharan Africa
# π Farm Size Prediction Across Sub-Saharan Africa
**Random Forest and Quantile Regression Forest models to predict farm size distributions and number of farms across Sub-Saharan Africa**
*Trained on ~180,000 LSMS farm surveys from 16 countries Β· Applied continent-wide at ~10 km resolution*
---
## π Overview
This project develops machine learning models to characterize the spatial distribution of smallholder farm sizes across Sub-Saharan Africa. Starting from harmonized LSMS household survey data, the pipeline builds Random Forest (RF) and Quantile Regression Forest (QRF) models that predict the full empirical distribution of farm sizes β not just the mean β in every 10Γ10 km grid cell across the continent.
| | |
|---|---|
| π **Spatial resolution** | 10 Γ 10 km grid cells |
| πΊοΈ **Spatial extent** | Sub-Saharan Africa (continent-wide) |
| πΎ **Training data** | ~180,000 farms Β· 16 countries Β· LSMS surveys |
| π€ **Models** | Random Forest Β· Quantile RF Β· ExtraTrees |
| π¦ **Languages** | R (statistical modelling, figures) Β· Python (ML pipeline) |
---
## π Quick Start
### Option 1 β Run Locally with Synthetic Data
The test suite uses synthetic stubs: randomly generated data that mimic the structure of real inputs. This verifies that the entire pipeline runs correctly without requiring real survey or spatial data.
> β οΈ Synthetic results are **not scientifically meaningful**. Use real data (Option 3) to reproduce the paper's findings.
```r
# Clone and enter the scripts directory
git clone
github.com
cd farm_size_analysis/scripts
# Generate synthetic stubs and run the full pipeline (~7 min)
Rscript 00.4_run_all_tests.R
```
### Option 2 β Run with GitHub Actions (No Local Setup)
1. **Fork** this repository
2. Navigate to **Actions** β **Test R Scripts** β **Run workflow**
3. The pipeline runs automatically on every push to `main`
The workflow uses synthetic stub data β no downloads needed.
### Option 3 β β¦