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.39184968 -1.8896158
#>  [2,]  0.16395013 -2.2863021
#>  [3,] -1.33942778  1.4722737
#>  [4,] -0.68681033  0.3922719
#>  [5,] -0.14532168  1.7592033
#>  [6,] -0.82508357  1.8600784
#>  [7,]  1.36565988 -1.0231871
#>  [8,]  0.86666410 -1.1346344
#>  [9,] -1.11591799  0.9673515
#> [10,]  0.31026094  1.1925840
#> [11,]  0.83419626 -1.5810329
#> [12,] -0.39045889  1.3636999
#> [13,] -0.22018607 -1.6445454
#> [14,]  1.13742368 -0.6410403
#> [15,]  0.05296152  0.1861346
#> [16,]  0.79893129 -0.3175221
#> [17,] -0.77310927  1.2788252
#> [18,]  0.01746671 -1.1095703
#> [19,]  0.58316629 -0.6341155
#> [20,]  0.16815202  0.8797567
#> [21,] -0.16529353  0.7925861
#> [22,]  0.11417787 -1.6938942
#> [23,] -1.14325125  1.8106948
#> attr(,"scaled:center")
#> [1] -11.4538671   0.6038069
#> 
#> $umap_results_tbl
#> # A tibble: 23 × 3
#>         x      y service_line                 
#>     <dbl>  <dbl> <chr>                        
#>  1  0.392 -1.89  Alcohol Abuse                
#>  2  0.164 -2.29  Bariatric Surgery For Obesity
#>  3 -1.34   1.47  CHF                          
#>  4 -0.687  0.392 COPD                         
#>  5 -0.145  1.76  CVA                          
#>  6 -0.825  1.86  Carotid Endarterectomy       
#>  7  1.37  -1.02  Cellulitis                   
#>  8  0.867 -1.13  Chest Pain                   
#>  9 -1.12   0.967 GI Hemorrhage                
#> 10  0.310  1.19  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.392 -1.89  Alcohol Abuse                 1       
#>  2  0.164 -2.29  Bariatric Surgery For Obesity 1       
#>  3 -1.34   1.47  CHF                           3       
#>  4 -0.687  0.392 COPD                          3       
#>  5 -0.145  1.76  CVA                           3       
#>  6 -0.825  1.86  Carotid Endarterectomy        3       
#>  7  1.37  -1.02  Cellulitis                    2       
#>  8  0.867 -1.13  Chest Pain                    2       
#>  9 -1.12   0.967 GI Hemorrhage                 3       
#> 10  0.310  1.19  Joint Replacement             3       
#> # ℹ 13 more rows
#>