Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

recover hclustgeo_disc() #32

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading