Skip to content

Commit

Permalink
Merge pull request #32 from stscl/dev
Browse files Browse the repository at this point in the history
recover `hclustgeo_disc()`
  • Loading branch information
SpatLyu authored Jan 6, 2025
2 parents 2c594c0 + a9b4422 commit 86b6b25
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
14 changes: 4 additions & 10 deletions R/stratification.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,10 @@ discretize_vector = \(x, n, method = 'natural',
#' please see `stats::hclust()`.
#' @param scale (optional) Whether to scaled the dissimilarities matrix, default is `TRUE`.
#' @param wt (optional) Vector with the weights of the observations. By default, `wt` is `NULL`.
#' @param cut (optional) Whether to cut the `hclust` tree, default is `TRUE`.
#' @param ... (optional) Other arguments passed to `stats::dist()`.
#'
#' @return When `cut` is `TRUE`, returns a grouped membership: a `vector` if `n` is a scalar,
#' a `matrix` (columns correspond to elements of `n`) if not; otherwise, returns a `vector`
#' of the permuted original observations.
#' @return The grouped membership: a `vector` if `n` is a scalar, a `matrix` (columns correspond to elements
#' of `n`) if not.
#' @export
#'
#' @examples
Expand All @@ -74,7 +72,7 @@ discretize_vector = \(x, n, method = 'natural',
#'
hclustgeo_disc = \(data, n, alpha = 0.5, D1 = NULL,
hclustm = "ward.D2", scale = TRUE,
wt = NULL, cut = TRUE, ...){
wt = NULL, ...){
if (inherits(data,"sf")) {
if (alpha != 0 & is.null(D1)) {
D1 = sdsfun::sf_distance_matrix(data)
Expand All @@ -89,9 +87,5 @@ hclustgeo_disc = \(data, n, alpha = 0.5, D1 = NULL,
deltadist = stats::as.dist(RcppHClustGeoMat(D0,D1,alpha,scale,wt))
resh = stats::hclust(deltadist,method = hclustm,members = wt)

if (cut) {
return(stats::cutree(resh,k = n))
} else {
return(resh$order)
}
return(stats::cutree(resh,k = n))
}
8 changes: 2 additions & 6 deletions man/hclustgeo_disc.Rd

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

0 comments on commit 86b6b25

Please sign in to comment.