Skip to content

Commit 485f305

Browse files
committed
fix warnings in examples
1 parent 987a9b6 commit 485f305

File tree

5 files changed

+15
-48
lines changed

5 files changed

+15
-48
lines changed

R/methods_hclust.R

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#' rows in data).
99
#' @param ... Arguments passed to or from other methods.
1010
#'
11-
#' @examplesIf require("factoextra", quietly = TRUE) && require("dbscan", quietly = TRUE) && require("cluster", quietly = TRUE) && require("fpc", quietly = TRUE)
11+
#' @examplesIf all(insight::check_if_installed(c("dbscan", "cluster", "fpc"), quietly = TRUE))
1212
#' \donttest{
1313
#' #
1414
#' # K-means -------------------------------
@@ -46,23 +46,6 @@
4646
#' attributes(rez)$Between_Sum_Squares
4747
#'
4848
#' #
49-
#' # Hierarchical K-means (factoextra::hkclust) ----------------------
50-
#' data <- iris[1:4]
51-
#' model <- factoextra::hkmeans(data, k = 3)
52-
#'
53-
#' rez <- model_parameters(model)
54-
#' rez
55-
#'
56-
#' # Get clusters
57-
#' predict(rez)
58-
#'
59-
#' # Clusters centers in long form
60-
#' attributes(rez)$means
61-
#'
62-
#' # Between and Total Sum of Squares
63-
#' attributes(rez)$Sum_Squares_Total
64-
#' attributes(rez)$Sum_Squares_Between
65-
#'
6649
#' # K-Medoids (PAM and HPAM) ==============
6750
#' model <- cluster::pam(iris[1:4], k = 3)
6851
#' model_parameters(model)

R/n_clusters_easystats.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
#' x <- n_clusters_elbow(iris[1:4])
55
#' x
66
#' as.data.frame(x)
7-
#' plot(x)
7+
#' # plotting is also possible:
8+
#' # plot(x)
89
#' }
910
#' @export
1011
n_clusters_elbow <- function(x,
@@ -93,7 +94,8 @@ n_clusters_gap <- function(x,
9394
#' x <- n_clusters_silhouette(iris[1:4])
9495
#' x
9596
#' as.data.frame(x)
96-
#' plot(x)
97+
#' # plotting is also possible:
98+
#' # plot(x)
9799
#' }
98100
#' }
99101
#' @export

man/model_parameters.hclust.Rd

Lines changed: 1 addition & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/n_clusters.Rd

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/clustering.Rmd

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
22
title: "Clustering with easystats"
3-
output:
3+
output:
44
rmarkdown::html_vignette:
55
vignette: >
66
%\VignetteIndexEntry{Clustering with easystats}
77
\usepackage[utf8]{inputenc}
88
%\VignetteEngine{knitr::rmarkdown}
9-
editor_options:
9+
editor_options:
1010
chunk_output_type: console
1111
---
1212

@@ -64,7 +64,7 @@ Clustering traditionally refers to the identification of groups of observations
6464

6565
There are many clustering algorithms (see [this for an overview](https://scikit-learn.org/stable/modules/clustering.html)), but they can grouped in two categories: **supervised** and **unsupervised** techniques. In **supervised** techniques, you have to explicitly specify [**how many clusters**](https://easystats.github.io/parameters/reference/n_clusters.html) you want to extract. **Unsupervised** techniques, on the other hand, will estimate this number as part of their algorithm. Note that there are no inherently superior and inferior clustering methods, each come with their sets of limitations and benefits.
6666

67-
As an example in the tutorial below, we will use the **iris** dataset, for which we know that there are 3 "real" clusters (the 3 Species of flowers). Let's first start with visualizing the 3 "real" clusters on a 2D space of the variables created through PCA.
67+
As an example in the tutorial below, we will use the **iris** dataset, for which we know that there are 3 "real" clusters (the 3 Species of flowers). Let's first start with visualizing the 3 "real" clusters on a 2D space of the variables created through PCA.
6868

6969

7070
```{r}
@@ -161,14 +161,11 @@ Hierarchical K-Means, as its name suggest, is essentially a combination of K-Mea
161161
rez_hkmeans <- cluster_analysis(data, n = 3, method = "hkmeans")
162162
163163
rez_hkmeans # Show results
164-
165-
# Visualize
166-
plot(rez_hkmeans) + theme_modern() # Visualize
167164
```
168165

169166
### K-Medoids (PAM)
170167

171-
Clustering around "medoids", instead of "centroid", is considered to be a more robust version of K-means. See `cluster::pam()` for more information.
168+
Clustering around "medoids", instead of "centroid", is considered to be a more robust version of K-means. See `cluster::pam()` for more information.
172169

173170
```{r}
174171
rez_pam <- cluster_analysis(data, n = 3, method = "pam")
@@ -203,7 +200,7 @@ plot(rez_hclust2) + theme_modern() # Visualize
203200

204201
### DBSCAN
205202

206-
Although the DBSCAN method is quite powerful to identify clusters, it is highly dependent on its parameters, namely, `eps` and the `min_size`. Regarding the latter, the minimum size of any cluster is set by default to `0.1` (i.e., 10\% of rows), which is appropriate to avoid having too small clusters.
203+
Although the DBSCAN method is quite powerful to identify clusters, it is highly dependent on its parameters, namely, `eps` and the `min_size`. Regarding the latter, the minimum size of any cluster is set by default to `0.1` (i.e., 10\% of rows), which is appropriate to avoid having too small clusters.
207204

208205
The "optimal" **eps** value can be estimated using the [`n_clusters_dbscan()`](https://easystats.github.io/parameters/reference/cluster_analysis.html) function:
209206

0 commit comments

Comments
 (0)