Association between land cover types and covariates


Exploring association between covariates used for land suitability modelling: with

  1. Full dataset
  2. Masking out urbanity

Load packages, read data and source custom scripts

rm(list = ls())
library(tidyr)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(ggplot2)
library(purrr)

path_proj <- day2day::git_path()
path_data <- file.path(path_proj, "data")
path_processed <- file.path(path_data, "processed")

source(file.path(path_proj, "src", "42-vis-assoc.R"))

Read and join datasets

files <- file.path(path_processed, c("uk_1km_dataframe_train_full.fst", "uk_1km_dataframe_train_maskout.fst"))
data_type <- sub("uk_1km_dataframe_train_(.+)\\.fst", "\\1", basename(files))

land_cover <- map2(files, data_type, ~ mutate(fst::read_fst(.x), data_type = .y)) %>%
    dplyr::bind_rows() %>%
    mutate_at(vars(matches("^count_[1-5]")), ~ . / count_no_urban)

Association with one-dimensional variables

covs <- c("gdd", "max_tas", "max_tasmax", "maxmonth_tas", "min_tas", "min_tasmin",
          "smd", "sms", "elev", "slope_nb8")
responses <- grep("^count_[1-5]", names(land_cover), value = TRUE)
classes <- stringr::str_to_sentence(gsub("_", " ", sub("^count_[0-9]_", "" ,responses)))
map2(responses, classes, ~ assoc_1d(.x, covs, land_cover, .y))
#> [[1]]

#> 
#> [[2]]

#> 
#> [[3]]

#> 
#> [[4]]

#> 
#> [[5]]

Association with two-dimensional variables

covs_2d <- c(tas_x = "min_tas", tas_y = "max_tas", sm_x = "smd", sm_y = "sms")
map2(responses, classes, ~ assoc_2d(.x, covs_2d, land_cover, .y))
#> [[1]]

#> 
#> [[2]]

#> 
#> [[3]]

#> 
#> [[4]]

#> 
#> [[5]]

Time to execute the task

Only useful when executed with Rscript.

proc.time()
#>    user  system elapsed 
#> 346.354  10.835 357.233