Skip to contents

Create a umap object from the uwot::umap() function.

Usage

hai_umap_list(.data, .kmeans_map_tbl, .k_cluster = 5)

umap_list(.data, .kmeans_map_tbl, .k_cluster = 5)

Arguments

.data

The data from the hai_kmeans_user_item_tbl() function.

.kmeans_map_tbl

The data from the hai_kmeans_mapped_tbl().

.k_cluster

Pick the desired amount of clusters from your analysis of the scree plot.

Value

A list of tibbles and the umap object

Details

This takes in the user item table/matix that is produced by hai_kmeans_user_item_tbl() function. This function uses the defaults of uwot::umap().

Author

Steven P. Sanderson II, MPH

Examples

library(healthyR.data)
library(dplyr)
library(broom)

data_tbl <- healthyR_data %>%
  filter(ip_op_flag == "I") %>%
  filter(payer_grouping != "Medicare B") %>%
  filter(payer_grouping != "?") %>%
  select(service_line, payer_grouping) %>%
  mutate(record = 1) %>%
  as_tibble()

uit_tbl <- hai_kmeans_user_item_tbl(
  .data = data_tbl,
  .row_input = service_line,
  .col_input = payer_grouping,
  .record_input = record
)

kmm_tbl <- hai_kmeans_mapped_tbl(uit_tbl)

umap_list(.data = uit_tbl, kmm_tbl, 3)
#> New names:
#>  `` -> `...1`
#>  `` -> `...2`
#> Joining with `by = join_by(service_line)`
#> $umap_obj
#>             [,1]       [,2]
#>  [1,]  0.3756617  1.6266386
#>  [2,]  1.2128247  1.6145231
#>  [3,] -1.2789301 -1.8276432
#>  [4,] -0.9147857  0.1789848
#>  [5,] -1.5418426 -0.9628437
#>  [6,] -0.7886008 -1.7511490
#>  [7,]  1.0354418  0.7103454
#>  [8,]  1.7965878  0.9313165
#>  [9,] -1.6583286 -1.5955647
#> [10,] -0.2247573 -0.6083411
#> [11,]  1.4786886  1.1960394
#> [12,] -1.2884568 -1.1867798
#> [13,]  0.7334341  1.2225553
#> [14,]  1.7564687  0.4660722
#> [15,] -0.4933723  0.1304485
#> [16,]  0.9683708  0.1873237
#> [17,] -1.0406839 -0.9888724
#> [18,]  0.4560446  0.8561479
#> [19,]  1.3455967  0.3654672
#> [20,] -1.1865085 -0.3827456
#> [21,] -0.6881925 -0.5083588
#> [22,]  0.8312610  1.8049146
#> [23,] -0.8859214 -1.4784792
#> attr(,"scaled:center")
#> [1]   4.197665 -12.600502
#> 
#> $umap_results_tbl
#> # A tibble: 23 × 3
#>         x      y service_line                 
#>     <dbl>  <dbl> <chr>                        
#>  1  0.376  1.63  Alcohol Abuse                
#>  2  1.21   1.61  Bariatric Surgery For Obesity
#>  3 -1.28  -1.83  CHF                          
#>  4 -0.915  0.179 COPD                         
#>  5 -1.54  -0.963 CVA                          
#>  6 -0.789 -1.75  Carotid Endarterectomy       
#>  7  1.04   0.710 Cellulitis                   
#>  8  1.80   0.931 Chest Pain                   
#>  9 -1.66  -1.60  GI Hemorrhage                
#> 10 -0.225 -0.608 Joint Replacement            
#> # ℹ 13 more rows
#> 
#> $kmeans_obj
#> K-means clustering with 3 clusters of sizes 5, 6, 12
#> 
#> Cluster means:
#>   Blue Cross Commercial Compensation Exchange Plans        HMO   Medicaid
#> 1  0.1495475 0.03679700 0.0003066332    0.020729565 0.16252855 0.13072521
#> 2  0.1170278 0.03141187 0.0101665392    0.013865190 0.09822472 0.08557952
#> 3  0.0783745 0.02182129 0.0043244347    0.006202137 0.04493860 0.03684344
#>   Medicaid HMO Medicare A Medicare HMO    No Fault    Self Pay
#> 1   0.31446157  0.1318675   0.03192357 0.001364577 0.019748398
#> 2   0.14652195  0.3535395   0.10524131 0.007067791 0.031353724
#> 3   0.08001653  0.5625037   0.15152338 0.003475542 0.009976485
#> 
#> Clustering vector:
#>  [1] 1 1 3 3 3 3 2 2 3 3 1 3 1 2 3 2 3 2 2 3 3 1 3
#> 
#> Within cluster sum of squares by cluster:
#> [1] 0.19152559 0.08456928 0.09625399
#>  (between_SS / total_SS =  73.6 %)
#> 
#> Available components:
#> 
#> [1] "cluster"      "centers"      "totss"        "withinss"     "tot.withinss"
#> [6] "betweenss"    "size"         "iter"         "ifault"      
#> 
#> $kmeans_cluster_tbl
#> # A tibble: 23 × 2
#>    service_line                  .cluster
#>    <chr>                         <fct>   
#>  1 Alcohol Abuse                 1       
#>  2 Bariatric Surgery For Obesity 1       
#>  3 CHF                           3       
#>  4 COPD                          3       
#>  5 CVA                           3       
#>  6 Carotid Endarterectomy        3       
#>  7 Cellulitis                    2       
#>  8 Chest Pain                    2       
#>  9 GI Hemorrhage                 3       
#> 10 Joint Replacement             3       
#> # ℹ 13 more rows
#> 
#> $umap_kmeans_cluster_results_tbl
#> # A tibble: 23 × 4
#>         x      y service_line                  .cluster
#>     <dbl>  <dbl> <chr>                         <fct>   
#>  1  0.376  1.63  Alcohol Abuse                 1       
#>  2  1.21   1.61  Bariatric Surgery For Obesity 1       
#>  3 -1.28  -1.83  CHF                           3       
#>  4 -0.915  0.179 COPD                          3       
#>  5 -1.54  -0.963 CVA                           3       
#>  6 -0.789 -1.75  Carotid Endarterectomy        3       
#>  7  1.04   0.710 Cellulitis                    2       
#>  8  1.80   0.931 Chest Pain                    2       
#>  9 -1.66  -1.60  GI Hemorrhage                 3       
#> 10 -0.225 -0.608 Joint Replacement             3       
#> # ℹ 13 more rows
#>