Skip to contents

Clustering is performed using add_clusters.

[Experimental]

Usage

cluster_tab(
  data,
  cols,
  newcol = NULL,
  k = NULL,
  method = "kmeans",
  labels = TRUE,
  clean = TRUE,
  ...
)

Arguments

data

A tibble.

cols

A tidy selection of item columns or a single column with cluster values as a factor or logical. If the column already contains a cluster result from add_clusters, it is used, and other parameters are ignored. If no cluster result exists, it is calculated with add_clusters.

newcol

Name of the new cluster column as a character vector. Set to NULL (default) to automatically build a name from the common column prefix, prefixed with "cls_".

k

Number of clusters to calculate. Set to NULL to automatically determine an optimal cluster number. For kmeans, the number of clusters is automatically chosed based on the elbow criterion after calculating within-sums of squares for up to 10 clusters. For pam, the number of clusters is automatically chosen based on the maximum average silhouette for up to 10 clusters.

method

The method as a character value, one of kmeans or pam. See add_clusters for further details.

labels

If TRUE (default) extracts labels from the attributes, see codebook.

clean

Prepare data by data_clean.

...

Placeholder to allow calling the method with unused parameters from tab_metrics.

Value

A volker list with with three volker tabs: cluster centers, cluster counts, and clustering diagnostics.

Examples

library(volker)
data <- volker::chatgpt

cluster_tab(data, starts_with("cg_adoption"), k = 2)
#> 
#> 
#> |Expectations                             |     total| Cluster 1| Cluster 2|
#> |:----------------------------------------|---------:|---------:|---------:|
#> |ChatGPT has clear advantages compared... | 3.4 (1.0)| 3.8 (0.9)| 3.1 (1.0)|
#> |Using ChatGPT brings financial benefits. | 2.7 (1.2)| 3.4 (1.0)| 2.0 (0.9)|
#> |Using ChatGPT is advantageous in many... | 3.6 (1.1)| 4.0 (0.7)| 3.1 (1.2)|
#> |Compared to other systems, using Chat... | 3.5 (1.0)| 3.9 (0.8)| 3.2 (1.0)|
#> |Much can go wrong when using ChatGPT.    | 3.1 (1.1)| 3.0 (1.1)| 3.2 (1.1)|
#> |There are legal issues with using Cha... | 3.1 (1.2)| 3.2 (1.1)| 3.0 (1.2)|
#> |The security of user data is not guar... | 3.2 (1.0)| 3.4 (1.0)| 3.0 (1.1)|
#> |Using ChatGPT could bring personal di... | 2.7 (1.1)| 2.9 (1.2)| 2.6 (1.0)|
#> |In my environment, using ChatGPT is s... | 2.5 (1.1)| 3.4 (0.9)| 1.7 (0.6)|
#> |Almost everyone in my environment use... | 2.4 (1.2)| 3.3 (0.9)| 1.6 (0.6)|
#> |Not using ChatGPT is considered being... | 2.0 (1.2)| 2.6 (1.3)| 1.4 (0.6)|
#> |Using ChatGPT brings me recognition f... | 2.3 (1.2)| 3.0 (1.3)| 1.7 (0.8)|
#> |n                                        |        97|        47|        50|
#> 
#> n=97. 4 missing case(s) omitted.
#> 
#> 
#> 
#> |Cluster   |  n|    p|
#> |:---------|--:|----:|
#> |Cluster 1 | 47|  48%|
#> |Cluster 2 | 50|  52%|
#> |total     | 97| 100%|
#> 
#> n=97.
#> 
#> 
#> 
#> |Statistic                      |  Value|
#> |:------------------------------|------:|
#> |Within-Cluster Sum of Squares  | 910.04|
#> |Between-Cluster Sum of Squares | 241.96|