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,
  ...
)

Arguments

formula

A formula of spatial stratified heterogeneity test.

data

A data.frame or tibble of observation data.

discnum

A vector of number of classes for discretization.

discmethod

(optional) A vector of methods for discretization,default is used c("sd","equal","pretty","quantile","fisher","headtails","maximum","box")in spEcula.

cores

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.

return_disc

(optional) Whether or not return discretized result used the optimal parameter. Default is TRUE.

...

(optional) Other arguments passed to st_unidisc().

Value

A list with the optimal parameter in the provided parameter combination with k, method and disc(when return_disc is TRUE).

Author

Wenbo Lv lyu.geosocial@gmail.com

Examples

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')
}