Chapter 5 Malawi and Zambia

zambia_sample_200 <- oversample_wrapper_pair(name = "Zambia",
                            bins = zambia_sampling_bin,
                            raster_1 = zambia_population,
                            raster_2 = zambia_population_1k,
                            raster_3 = zambia_population_5k,
                            random_number = 680,
                            original_min_unit3 = 1,
                            original_sample_unit3 = 100,
                            by_factor=1.1,
                            verbose=2)

malawi_sample_200 <- oversample_wrapper_pair(name = "Malawi",
                            bins = maw_sampling_bin,
                            raster_1 = malawi_population,
                            raster_2 = malawi_population_1k,
                            raster_3 = malawi_population_5k,
                            random_number = 680,
                            original_min_unit3 = 1,
                            original_sample_unit3 = 100,
                            by_factor=1.1,
                            verbose=2)
respondents_per_bin <- function(sp_obj,name,onlydf=FALSE) {
  if (any("Unit_3"==sp_obj$type)) {

    tab1 <- sp_obj %>% 
    st_as_sf() %>% 
    filter(pick=="Sample"&type=="Unit_3") %>% 
    mutate(Bin = sapply(Name,function(x) {
      strsplit(x,"@") %>% 
        lapply(function(y) y[2]) %>% 
        unlist()
    })) %>% 
    as.data.frame() %>% 
    group_by(Bin) %>% 
    summarise(`Sampling Units`=n()) %>% 
    mutate(`Number of Households` = `Sampling Units` * 50) %>% 
    mutate(Bin = as.numeric(Bin)) %>% 
    arrange(Bin)
} else {
  tab1 <- sp_obj %>% 
    st_as_sf() %>% 
    filter(pick=="Sample"&type!="Bin") %>% 
    mutate(Bin = sapply(Name,function(x) {
      strsplit(x,"@") %>% 
        lapply(function(y) y[2]) %>% 
        unlist()
    })) %>% 
    as.data.frame() %>% 
    group_by(Bin) %>% 
    summarise(`Sampling Units`=n()) %>% 
    mutate(`Number of Households` = `Sampling Units` * 25) %>% 
    mutate(Bin = as.numeric(Bin)) %>% 
    arrange(Bin)
}
  if(onlydf) return(tab1)
  
  kable(tab1,caption = paste0("Number of Respondents and sampling units in ",
                              name,". (n = ",
                              tab1 %$% 
                                sum(`Number of Households`),")")) %>% 
  kable_styling(full_width = FALSE,position = "left")
  
}
nairobi_sample_150 %>% 
  respondents_per_bin("Nairobi") 

Table 5.1: Number of Respondents and sampling units in Nairobi. (n = 3750)

Bin Sampling Units Number of Households
1 17 425
2 46 1150
3 22 550
4 23 575
5 10 250
6 22 550
7 8 200
8 2 50
lusaka_sample_150 %>% 
  respondents_per_bin("Lusaka") 

Table 5.1: Number of Respondents and sampling units in Lusaka. (n = 3750)

Bin Sampling Units Number of Households
1 24 600
2 45 1125
3 33 825
4 24 600
5 4 100
6 7 175
7 7 175
8 6 150
lilongwe_sample_150 %>% 
  respondents_per_bin("Lilongwe") 

Table 5.1: Number of Respondents and sampling units in Lilongwe. (n = 3750)

Bin Sampling Units Number of Households
1 18 450
2 16 400
3 26 650
4 13 325
5 20 500
6 22 550
7 18 450
8 17 425
zambia_sample_200 %>% 
  respondents_per_bin("Zambia")

Table 5.1: Number of Respondents and sampling units in Zambia. (n = 5000)

Bin Sampling Units Number of Households
1 10 500
2 12 600
3 12 600
4 9 450
5 23 1150
6 6 300
7 7 350
8 4 200
9 7 350
10 10 500
malawi_sample_200 %>% 
  respondents_per_bin("Malawi")

Table 5.1: Number of Respondents and sampling units in Malawi. (n = 5000)

Bin Sampling Units Number of Households
1 21 1050
2 7 350
3 11 550
4 8 400
5 10 500
6 10 500
7 11 550
8 6 300
9 11 550
10 5 250