njtierney / maxcovr

Tools in R to make it easier to solve the Maximal Coverage Location Problem
http://maxcovr.njtierney.com/
GNU General Public License v3.0
43 stars 12 forks source link

Summarising and comparing coverage pre and post model #7

Open njtierney opened 8 years ago

njtierney commented 8 years ago

OK just while I remember, there need to be a couple of functions that assist in viewing the coverage from the model, before and after.

First function, table_coverage, looks like the following

table_coverage <- function(x, dist_indic = 100){

    x %>%
        count(is_covered = distance < dist_indic)  %>%
        mutate(is_covered = if_else(is_covered == TRUE,
                                    true = "Covered", 
                                    false = "Not Covered")) %>%
        mutate(pct = n / sum(n)) %>%
        rename(n_cov = n,
               pct_cov = pct)
}

However, it requires a prespecified object, x, which would be the distances between facilities (AEDs) and users (OHCAs) in it's wide form, and the variable is_covered. Ideally this distance calculation can be performed quickly using some nifty c++ code, so that this function doesn't grind and grind.

Then there's model_coverage and the subsequent tidying functions to produce tables. These need to be


dat_dist <- facility_user_dist(facility, user)

original_coverage <- table_coverage(dat_dist, 100)

model_coverage <- function(dat_facility,
                           dat_user,
                           mc_model){
    dat_user %>%
    bind_rows(mc_model$facility_selected) %>%
    facility_user_dist(user = dat_facility) %>%
    table_coverage()
}

This final function assumes that the model coverage problem has been mapped over a few different n_aed levels, and produces a table of how coverage changes from n_aeds = 20 ... 100.

Would be really cool to functionalise this.


coverage_over_n_aed <- original_coverage %>%
  bind_rows(list_covr) %>%
    filter(is_covered == "Covered") %>%
  mutate(type = c("prior_optimisation",
                  "optimised_n20",
                  "optimised_n40",
                  "optimised_n60",
                  "optimised_n80",
                  "optimised_n100")) %>% 
    mutate(n_aed_added = c(
        0,
        20,
        40,
        60,
        80,
        100
    )) %>%
    select(type,n_aed_added, n_cov,pct_cov)
njtierney commented 7 years ago

Added a summarise_coverage() function in commit https://github.com/njtierney/maxcovr/commit/a6a78702de2ff167315b393d7a4901ccc1873645

Need to make an alias to be summarize_coverage().