Exploratory linear models
Simple univariate GAM models to evaluate the relationship between each land category and covariates.
Load packages, read data and source custom scripts
rm(list = ls())
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(mgcv)
#> Loading required package: nlme
#>
#> Attaching package: 'nlme'
#> The following object is masked from 'package:dplyr':
#>
#> collapse
#> This is mgcv 1.8-31. For overview type 'help("mgcv-package")'.
library(purrr)
path_proj <- day2day::git_path()
path_data <- file.path(path_proj, "data")
path_processed <- file.path(path_data, "processed")
path_modelled <- file.path(path_data, "modelled")
land_cover <- fst::read_fst(file.path(path_processed, "uk_1km_df_model_maskout.fst"))
land_cover <- sample_n(land_cover, 5000)
Exploratory model of land classes with covariates
make_form <- function(land_type, term) {
paste0("cbind(", land_type, ", count_no_urban - ", land_type, ") ~ s(", term, ")")
}
data_model <- as_tibble(expand.grid(
land_type = tidyselect::vars_select(names(land_cover), matches("^count_[1-5]")),
term = c("elev", "slope_nb8", "gdd", "max_tasmax,min_tasmin", "smd,sms"),
stringAsFactors = FALSE))
data_model <- data_model %>%
mutate(
formula = map(make_form(land_type, term), as.formula),
model = map(formula, safely(~ gam(., binomial(), land_cover)))
)
save(data_model, file = file.path(path_modelled, "explo-binoms-uni.rds"))
Time to execute the task
Only useful when executed with Rscript
.
proc.time()
#> user system elapsed
#> 14.811 0.156 14.986