Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
58a571d
chore: gitignore data dir and Rproj file
TSGreen Jan 1, 2026
cd7e64d
feat: Add script for package installation
TSGreen Jan 1, 2026
550946e
refactor: Update file paths for ONS versions
TSGreen Jan 1, 2026
67976a7
refactor: Enable execution of 00 script on local machines
TSGreen Jan 9, 2026
65b4f29
Add MIT License to the project
TSGreen Jan 9, 2026
66ab0b2
refactor: Update building mosaic script for compatibility with existi…
TSGreen Jan 9, 2026
18f3df7
Merge branch 'main' into ons-compatability-updates
TSGreen Jan 9, 2026
14b7eb0
refactor: Update paths to EA shapefiles and data dir
TSGreen Jan 15, 2026
2a43a7a
Merge branch 'wpgp:main' into main
TSGreen Jan 28, 2026
fcfeac1
Merge branch 'main' into ons-compatability-updates
TSGreen Jan 29, 2026
4cfbede
List of covariets needed for model and urls to access data in WP website
abaizan Jan 27, 2026
ca20e65
Script to download data using urls and datalog showing which ones wer…
abaizan Jan 27, 2026
5975b6f
Added path to covariate
abaizan Feb 4, 2026
2df0710
feat: Output 10km buffered country boundary geometry
TSGreen Feb 5, 2026
3415fcd
refactor: Enable building raster mosaicing
TSGreen Feb 6, 2026
5e20b8a
refactor: Enable covariate mosaicing
TSGreen Feb 9, 2026
89e7685
refactor: Enable run through of 00 preprocessing scripts
TSGreen Feb 11, 2026
066bd84
Changed shapefile from "2018_MPHC_EAs_Final_for_Use_Corrected.shp" to…
abaizan Mar 26, 2026
64d4cb8
Added correct file name for shapefile
abaizan Mar 26, 2026
b7128d4
Changed readme to be more useful
abaizan Mar 26, 2026
3cd0fa9
extra package needed to run HH modelling
abaizan Apr 21, 2026
c2b7b51
Improved readme
abaizan Apr 21, 2026
0bbbb7b
refactor: Update names of covars in rast object to match file naming
TSGreen Apr 21, 2026
9e65e7c
Added "glmnet" as one of the packages to install
abaizan May 4, 2026
ae7b445
zomba data processing function in utils and added processing step to …
abaizan May 4, 2026
8a3a37f
Added message to say that malemia data is available
abaizan May 4, 2026
1ea5407
Updated readme to remove "missing files" flag
abaizan May 4, 2026
adbd1d0
Standardize household identifier and row-bind all TA CSVs into a sing…
Dogus-Can-Oksuz May 11, 2026
153917c
change the generate buffered country boundry function in utils to hav…
abaizan May 21, 2026
51a3305
updated zomba data merge
Dogus-Can-Oksuz Jun 5, 2026
18ee4a1
Spacified 10km buffer in raster mosaicking scripts
abaizan Jun 10, 2026
a31c9f1
Added country file with no buffer to rasterize.R script
abaizan Jun 10, 2026
921219a
Added documentation on new data and running
abaizan Jun 10, 2026
1177de4
Merge pull request #2 from datasciencecampus/ons-malemia_zomba_proces…
abaizan Jun 11, 2026
7bb5a42
Found an issue between loading the country file and creating it - whi…
abaizan Jun 17, 2026
0fff343
Merge pull request #4 from datasciencecampus/ons-compatibility-countr…
abaizan Jul 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata

*.Rproj

data/*
71 changes: 39 additions & 32 deletions 00_Data_Processing.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Data exploration workflow for dataset recived
# Data exploration workflow for dataset received

#load packages
library(sf)
Expand All @@ -9,21 +9,41 @@ library(tidyverse)
options(scipen = 999) # turn off scientific notation for all variables

#Specify Drive Path
drive_path <- "//Internal_Path/"
input_path <- paste0(drive_path, "Input_Data/Surveys/")
output_path <- paste0(drive_path, "/Output_Data/")
shapefile_path <- paste0(drive_path, "Input_Data/Shapefiles/")
drive_path <- "./data"
input_path <- file.path(drive_path, "MNSO-Data")
output_path <- file.path(drive_path, "Output_Data")
shapefile_path <- file.path(drive_path, "Shapefiles")

#Load datasets
mphc_2018 <- read_dta(paste0(input_path, "mphc2018Data_AllRegions.dta"))
mphc_structures_2018 <- read_dta(paste0(input_path, "mphc2018Data_structures.dta"))
ICT_data <- read_dta(paste0(input_path, "ICT Listing WorldPop.dta"))
IHS6_data <- read_dta(paste0(input_path, "IHS6 Listing WorldPop.dta"))
Naca_data <- read_dta(paste0(input_path, "Naca Listing WorldPop.dta"))
ea <- st_read(file.path(shapefile_path, "2018_MPHC_EAs_Final_for_Use_Corrected.shp"))
mphc_structures_2018 <- st_read(paste0(output_path, "mphc_structures_points.gpkg"))
dhs_data <- read_dta(paste0(input_path, "MDHS_2024_NoDZLK_anonymized.dta"))
dhs_listing <- read_dta(paste0(input_path, "FINAL MDHS LISTING DATA_Annon.dta"))
mphc_2018 <- read_dta(file.path(input_path, "mphc2018Data_AllRegions.dta"))
mphc_structures_2018 <- read_dta(file.path(input_path, "mphc2018Data_structures.dta"))
ICT_data <- read_dta(file.path(input_path, "ICT Listing WorldPop.dta"))
IHS6_data <- read_dta(file.path(input_path, "IHS6 Listing WorldPop.dta"))
Naca_data <- read_dta(file.path(input_path, "Naca Listing WorldPop.dta"))
ea <- st_read(file.path(shapefile_path, "2018_MPHC_EAs_Final_for_Use.shp")) # replaces "2018_MPHC_EAs_Final_for_Use_Corrected.shp"
dhs_data <- read_dta(file.path(input_path, "MDHS_2024_NoDZLK_anonymized.dta"))
dhs_listing <- read_dta(file.path(input_path, "FINAL MDHS LISTING DATA_Annon.dta"))

mphc_structures_2018_filepath <- file.path(
output_path, "mphc_structures_points.gpkg")

if (!file.exists(mphc_structures_2018_filepath)) {
#Structures
#Convert to sf object
mphc_structures_sf <- mphc_structures_2018 |>
drop_na(st_longitude, st_latitude) |>
st_as_sf(coords = c("st_longitude", "st_latitude"))

#set the spatial reference
st_crs(mphc_structures_sf ) <- 4326

# Write to GPKG file
st_write(mphc_structures_sf ,
dsn = file.path(output_path, "mphc_structures_points.gpkg"),
driver = "GPKG",
delete_layer = TRUE)
}
mphc_structures_2018 <- st_read(file.path(output_path, "mphc_structures_points.gpkg"))

# Write each data as a shapefile -----------------------------------------

Expand All @@ -41,20 +61,7 @@ dhs_listing <- read_dta(paste0(input_path, "FINAL MDHS LISTING DATA_Annon.dta"))
# driver = "GPKG",
# delete_layer = TRUE) # overwrite if layer already exists
#
# #Structures
# #Convert to sf object
# mphc_structures_sf <- mphc_structures_2018 |>
# drop_na(st_longitude, st_latitude) |>
# st_as_sf(coords = c("st_longitude", "st_latitude"))
#
# #set the spatial reference
# st_crs(mphc_structures_sf ) <- 4326
#
# # Write to GPKG file
# st_write(mphc_structures_sf ,
# dsn = file.path(output_path, "mphc_structures_points.gpkg"),
# driver = "GPKG",
# delete_layer = TRUE)

#
# #ICT
# ICT_sf <- ICT_data |>
Expand Down Expand Up @@ -179,7 +186,7 @@ mphc_pop_per_ea <- mphc_2018 |>
female_count = sum(p03 == 2, na.rm = TRUE))


#Create a bin for each age catgeory
#Create a bin for each age category
age_summary <- mphc_2018 |>
mutate(age_group = case_when(
p05 < 1 ~ "age_group_01_less", #less than 1
Expand Down Expand Up @@ -333,13 +340,13 @@ combined_data <- combined_data |>

#Write to file

write.csv(combined_data, paste0(output_path, "summarized_survey_data.csv"), row.names = F)
write.csv(combined_data, file.path(output_path, "summarized_survey_data.csv"), row.names = F)


#join combined data to EA shapefile and export
#Join to ea data
combined_data <- combined_data |>
mutate(EA_CODE = as.character(EA_CODE)) #convert EA code to interger
mutate(EA_CODE = as.character(EA_CODE)) #convert EA code to integer

#select hh size
hh_size <- combined_data |>
Expand All @@ -352,7 +359,7 @@ hh_ea <- hh_ea |>
select(EA_CODE, mphc_total_pop, hh_size)

#write to file
st_write(hh_ea, paste(output_path, "hh_size_data.shp"))
st_write(hh_ea, file.path(output_path, "hh_size_data.shp"))



Expand Down
Loading