Skip to content

Commit

Permalink
Merge pull request #19 from stscl/dev
Browse files Browse the repository at this point in the history
update `hclustgeo_disc()`
  • Loading branch information
SpatLyu authored Nov 26, 2024
2 parents 1b31078 + 4df6de0 commit 6ce5f34
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# sdsfun 0.6.0

* The aggregation method for hierarchical clustering in `hclustgeo_disc()` is set
to `ward.D2` by default (#18).

# sdsfun 0.5.0

* Add `hclustgeo_disc` for hierarchical clustering with spatial soft constraints (#13).
Expand Down
7 changes: 5 additions & 2 deletions R/stratification.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ discretize_vector = \(x, n, method = 'natural',
#' @param D1 (optional) A `matrix` with other dissimilarities between the same observations data. if `data`
#' is an `sf` object and alpha is not `0`, the `D1` will be generated by `sdsfun::sf_distance_matrix()`,
#' others will use a `matrix` with all elements equal to `0`.
#' @param hclustm (optional) The agglomeration method to be used, default is `ward.D2`. For more details,
#' 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 ... (optional) Other arguments passed to `stats::dist()`.
Expand All @@ -69,7 +71,8 @@ discretize_vector = \(x, n, method = 'natural',
#' plot(gzma["group"])
#'
hclustgeo_disc = \(data, n, alpha = 0.5, D1 = NULL,
scale = TRUE, wt = NULL, ...){
hclustm = "ward.D2", scale = TRUE,
wt = NULL, ...){
if (inherits(data,"sf")) {
if (alpha != 0 & is.null(D1)) {
D1 = sdsfun::sf_distance_matrix(data)
Expand All @@ -82,6 +85,6 @@ hclustgeo_disc = \(data, n, alpha = 0.5, D1 = NULL,
}
D0 = as.matrix(stats::dist(data,...))
deltadist = stats::as.dist(RcppHClustGeoMat(D0,D1,alpha,scale,wt))
resh = stats::hclust(deltadist,method="ward.D",members=wt)
resh = stats::hclust(deltadist,method=hclustm,members=wt)
return(stats::cutree(resh,k = n))
}
14 changes: 13 additions & 1 deletion 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 6ce5f34

Please sign in to comment.