Skip to content

Commit

Permalink
fix #39
Browse files Browse the repository at this point in the history
  • Loading branch information
SpatLyu committed Jan 9, 2025
1 parent 5e03ce5 commit 2350a6f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 29 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export(cpsd_spade)
export(ecological_detector)
export(factor_detector)
export(gd)
export(gd_bestunidisc)
export(gd_optunidisc)
export(gen_permutations)
export(geodetector)
export(gozh)
Expand Down
20 changes: 9 additions & 11 deletions R/gd_bestunidisc.R → R/gd_optunidisc.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#' @title best univariate discretization based on geodetector q-statistic
#' @title optimal univariate discretization based on geodetector q-statistic
#' @author Wenbo Lv \email{[email protected]}
#' @description
#' Function for determining the best univariate discretization based on geodetector q-statistic.
#'
#' @param formula A formula of best univariate discretization.
#' @param formula A formula.
#' @param data A `data.frame`, `tibble` or `sf` object of observation data.
#' @param discnum (optional) A vector of number of classes for discretization. Default is `3:8`.
#' @param discnum (optional) A vector of numbers of discretization. Default is `3:8`.
#' @param discmethod (optional) A vector of methods for discretization, default is using
#' `c("sd","equal","geometric","quantile","natural")` by invoking `sdsfun`.
#' @param cores (optional) Positive integer (default is 1). When cores are greater than 1, use
Expand All @@ -25,13 +23,13 @@
#'
#' @examples
#' data('sim')
#' gd_bestunidisc(y ~ xa + xb + xc,
#' data = sim,
#' discnum = 3:6)
#' gd_optunidisc(y ~ xa + xb + xc,
#' data = sim,
#' discnum = 3:6)
#'
gd_bestunidisc = \(formula, data, discnum = 3:8,
discmethod = c("sd","equal","geometric","quantile","natural"),
cores = 1, seed = 123456789, ...){
gd_optunidisc = \(formula, data, discnum = 3:8,
discmethod = c("sd","equal","geometric","quantile","natural"),
cores = 1, seed = 123456789, ...){
doclust = FALSE
if (cores > 1) {
doclust = TRUE
Expand Down
8 changes: 3 additions & 5 deletions R/opgd.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#' @title optimal parameters-based geographical detector(OPGD) model
#' @author Wenbo Lv \email{[email protected]}
#' @description
#' Function for optimal parameters-based geographical detector(OPGD) model.
#' @references
#' Song, Y., Wang, J., Ge, Y. & Xu, C. (2020) An optimal parameters-based geographical detector
#' model enhances geographic characteristics of explanatory variables for spatial heterogeneity
Expand Down Expand Up @@ -55,9 +53,9 @@ opgd = \(formula, data, discvar = NULL, discnum = 3:8,
discvar = colnames(data)[-which(colnames(data) == yname)]
}
discdf = dplyr::select(data,dplyr::all_of(c(yname,discvar)))
g = gd_bestunidisc(paste0(yname,'~',paste0(discvar,collapse = '+')),
data = discdf, discnum = discnum,
discmethod = discmethod, cores = cores, ...)
g = gd_optunidisc(paste0(yname,'~',paste0(discvar,collapse = '+')),
data = discdf, discnum = discnum,
discmethod = discmethod, cores = cores, ...)
opt_param = tibble::as_tibble(g[1:3])
names(opt_param) = c("varibale","discnum","method")
discedvar = colnames(data[,-which(colnames(data) %in% discvar)])
Expand Down
22 changes: 11 additions & 11 deletions man/gd_bestunidisc.Rd → man/gd_optunidisc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/opgd.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2350a6f

Please sign in to comment.