ar_cluster_targets
produces a target clustering based on the associatoR object's target embedding.
Usage
ar_cluster_targets(
associations,
method = "louvain",
similarity = "arccos",
k = NULL,
linkage = NULL,
eps = NULL,
...
)
Arguments
- associations
an
associatoR
object including target_embeddings.- method
a
character
specifying the clustering method. One ofc("louvain", "hclust", "kmeans", "dbscan")
. Default is"louvain"
.- similarity
a
character
specifying the similarity metric. One ofc("arccos", "cosine", "euclidean")
. Default is"arccos"
.- k
an
integer
specifying the number of clusters formethod = c("hclust", "kmeans")
.- linkage
a
character
specifying the linkage criterion formethod = c("hclust")
. Default is"complete"
.- eps
a
numeric
specifying the point distance used inmethod = c("dbscan")
.- ...
additional attributes passed on to the clustering method.
Value
The function returns the associatoR
object including a new
clusters
column in targets
containing the target clusters.
Examples
ar_import(intelligence,
participant = participant_id,
cue = cue,
response = response,
participant_vars = c(gender, education),
response_vars = c(response_position, response_level)) %>%
ar_set_targets(targets = "cues") %>%
ar_embed_targets() %>%
ar_cluster_targets(method = "louvain")
#> 456 targets with count < min_count were dropped from embedding.
#>
#> ── An associatoR object ────────────────────────────────────────────────────────
#>
#> participants
#> # A tibble: 1,000 × 3
#> id gender education
#> <dbl> <chr> <chr>
#> 1 1 male high school
#> 2 2 male high school
#> 3 3 male high school
#> 4 4 male high school
#> 5 5 male high school
#> # ℹ 995 more rows
#>
#> cues
#> # A tibble: 804 × 1
#> cue
#> <chr>
#> 1 intelligence
#> 2 Einstein
#> 3 books
#> 4 IQ tests
#> 5 college
#> # ℹ 799 more rows
#>
#> responses
#> # A tibble: 29,882 × 5
#> id cue response response_position response_level
#> <dbl> <chr> <chr> <dbl> <dbl>
#> 1 1 intelligence Einstein 1 1
#> 2 1 intelligence books 2 1
#> 3 1 intelligence IQ tests 3 1
#> 4 1 intelligence college 4 1
#> 5 1 intelligence smart people 5 1
#> # ℹ 29,877 more rows
#>
#> targets
#> # A tibble: 804 × 2
#> target cluster
#> <chr> <chr>
#> 1 intelligence cluster_1
#> 2 Einstein cluster_2
#> 3 books cluster_3
#> 4 IQ tests cluster_1
#> 5 college cluster_3
#> # ℹ 799 more rows
#>
#> target_embedding
#> # A tibble: 348 × 101
#> target dim_1 dim_2 dim_3 dim_4 dim_5 dim_6 dim_7 dim_8 dim_9
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 intell… 4.15 0.283 -2.03 3.25 -2.59 0.775 1.67 -0.227 1.28
#> 2 Einste… 1.73 0.462 -0.532 0.209 -4.59 -1.75 2.92 -0.333 -1.55
#> 3 books 11.3 -3.82 -0.507 -22.6 -7.53 8.45 -1.82 4.80 6.00
#> 4 IQ tes… 6.63 -1.50 -7.86 7.63 -2.27 9.65 14.6 4.16 -6.55
#> 5 college 8.24 -6.60 6.98 -7.41 7.06 0.863 8.66 -9.98 -0.438
#> # ℹ 343 more rows
#> # ℹ 91 more variables: dim_10 <dbl>, dim_11 <dbl>, dim_12 <dbl>,
#> # dim_13 <dbl>, dim_14 <dbl>, dim_15 <dbl>, dim_16 <dbl>,
#> # dim_17 <dbl>, dim_18 <dbl>, dim_19 <dbl>, dim_20 <dbl>,
#> # dim_21 <dbl>, dim_22 <dbl>, dim_23 <dbl>, dim_24 <dbl>,
#> # dim_25 <dbl>, dim_26 <dbl>, dim_27 <dbl>, dim_28 <dbl>,
#> # dim_29 <dbl>, dim_30 <dbl>, dim_31 <dbl>, dim_32 <dbl>, …
#>