R/discretization.R
gd_bestunidisc.Rd
Function for determining the best univariate discretize parameters based on geodetector q-statistic.
gd_bestunidisc(
formula,
data,
discnum,
discmethod = NULL,
cores = 1,
return_disc = TRUE,
...
)
A formula of spatial stratified heterogeneity test.
A data.frame or tibble of observation data.
A vector of number of classes for discretization.
(optional) A vector of methods for discretization,default is used
c("sd","equal","pretty","quantile","fisher","headtails","maximum","box")
in spEcula
.
positive integer(default is 1). If cores > 1, a 'parallel' package cluster with that many cores is created and used. You can also supply a cluster object.
(optional) Whether or not return discretized result used the optimal parameter.
Default is TRUE
.
(optional) Other arguments passed to st_unidisc()
.
A list with the optimal parameter in the provided parameter combination with k
,
method
and disc
(when return_disc
is TRUE
).
if (FALSE) {
library(terra)
library(tidyverse)
fvcpath = system.file("extdata", "FVC.zip",package = 'spEcula')
fvc = terra::rast(paste0("/vsizip/",fvcpath))
fvc = as_tibble(terra::as.data.frame(fvc,na.rm = T))
g = gd_bestunidisc(fvc ~ .,data = select(fvc,-lulc),discnum = 2:15,cores = 6)
new.fvc = g$disv
new.fvc = bind_cols(select(fvc,fvc,lulc),new.fvc)
ssh.test(fvc ~ .,data = new.fvc,type = 'factor')
ssh.test(fvc ~ .,data = new.fvc,type = 'interaction')
}