Load the libraries + functions

library(readr)
library(cluster)
library(pvclust)
library(reticulate)
py_config()
## python:         C:/Users/raavi/AppData/Local/r-miniconda/envs/r-reticulate/python.exe
## libpython:      C:/Users/raavi/AppData/Local/r-miniconda/envs/r-reticulate/python36.dll
## pythonhome:     C:/Users/raavi/AppData/Local/r-miniconda/envs/r-reticulate
## version:        3.6.11 (default, Aug  5 2020, 19:41:03) [MSC v.1916 64 bit (AMD64)]
## Architecture:   64bit
## numpy:          C:/Users/raavi/AppData/Local/r-miniconda/envs/r-reticulate/Lib/site-packages/numpy
## numpy_version:  1.19.1

The Data

The data for this assignment is tweets from US governors at the beginning of the pandemic (refer back to the Correspondence Analysis lecture). The dataset for this assignment includes basic info about each governor (state, name, party) and whether or not they used 1000 specific words in their tweets about COVID. Columns 4 to 1004 represent this words and are coded 0 (was not used in tweets) or 1 (was used in tweets). The goal of the current assignment is to explore the clusters of terms used in governors’ tweets about COVID.

gov_tweets <- read_csv("C:/Users/raavi/Dropbox/Harrisburg University/Semester 3/ANLY 540 Language Modeling/Week 5/Gov Tweets.csv")
## Parsed with column specification:
## cols(
##   .default = col_double(),
##   State = col_character(),
##   Governor = col_character(),
##   Party = col_character()
## )
## See spec(...) for full column specifications.
row.names(gov_tweets) = gov_tweets$State
## Warning: Setting row names on a tibble is deprecated.
gov_tweets <- gov_tweets[, -c(1,2,3)]
df = gov_tweets[,c(7:57)]
df <- t(df)
df
##              [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
## industry        1    1    0    1    1    1    1    1    0     0     0     0
## sector          1    1    0    1    0    1    0    1    1     1     0     0
## affect          0    0    1    1    1    1    1    1    0     1     0     1
## crisis          0    0    0    1    1    1    0    1    0     1     0     0
## important       1    1    1    1    1    1    1    1    0     0     1     1
## continue        1    1    1    1    1    1    1    1    1     1     1     1
## support         1    0    1    1    1    1    1    1    0     1     0     1
## protect         1    1    1    1    1    1    1    1    1     1     1     1
## people          1    1    1    1    1    1    1    1    1     1     1     1
## threat          0    0    1    1    1    0    0    0    0     1     0     0
## longer          0    0    0    1    0    0    0    1    0     0     0     0
## imminent        0    0    0    1    1    0    0    0    0     0     0     0
## urllink         1    1    1    1    1    1    1    1    1     1     1     1
## live            1    1    1    1    1    1    1    1    1     1     1     1
## governor        0    0    1    1    1    1    1    1    0     1     1     0
## provide         1    0    1    1    1    1    1    1    1     1     1     1
## update          1    1    1    1    1    1    1    1    1     1     0     0
## media           0    0    0    1    1    1    1    0    0     0     1     0
## hold            0    0    1    1    0    1    0    1    1     0     0     1
## news            0    0    0    1    1    1    1    0    1     1     1     0
## conference      0    0    0    1    0    1    1    1    0     1     0     1
## X1.30           0    0    0    1    0    0    0    1    0     0     0     0
## pm              0    0    0    1    1    0    1    1    1     1     0     0
## today           0    1    1    1    1    1    1    1    1     1     1     1
## response        0    0    1    1    1    1    1    1    1     1     1     1
## watch           0    0    0    1    1    1    1    1    1     1     1     1
## faith           0    0    0    1    1    0    1    0    0     0     0     0
## community       1    1    1    1    1    1    1    1    1     1     1     1
## effort          1    0    1    1    1    1    1    1    1     1     1     1
## fight           1    1    0    1    1    1    1    1    0     1     1     1
## in.person       0    0    1    1    0    0    1    0    0     0     0     0
## fellowship      0    0    0    1    1    0    0    0    0     0     0     0
## church          0    0    1    1    0    0    0    0    0     0     0     0
## meet            1    1    1    1    1    1    0    1    0     1     0     1
## remotely        0    0    0    1    0    0    0    0    0     0     1     0
## present         0    0    0    1    0    1    1    0    0     0     0     1
## guidance        1    0    1    1    1    1    1    1    0     1     1     0
## give            0    1    1    1    1    1    1    1    1     0     0     0
## house           0    1    1    1    1    1    1    1    0     0     1     1
## worship         0    0    1    1    1    0    1    0    0     1     0     0
## option          0    0    1    1    1    0    1    0    0     0     0     1
## congregation    0    0    0    1    0    0    0    0    0     0     0     0
## thank           1    0    1    1    1    1    1    1    1     1     1     1
## X.walmart       0    0    0    1    0    0    0    0    0     0     0     0
## quest           0    0    0    1    0    0    0    0    0     0     0     0
## diagnostic      0    0    0    1    0    0    0    0    0     0     0     0
## opening         0    0    1    1    1    1    1    0    0     0     0     0
## drive.thru      0    0    0    1    0    0    0    1    0     0     0     0
## test            1    1    1    1    1    1    1    1    1     1     1     1
## site            1    1    1    1    1    1    1    0    1     1     0     0
## central         0    0    0    1    0    0    0    0    0     0     0     0
##              [,13] [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23]
## industry         1     0     0     0     0     0     0     1     0     0     0
## sector           0     1     0     0     0     0     0     1     1     0     0
## affect           1     1     1     1     1     1     0     1     0     0     0
## crisis           1     1     1     1     1     1     1     1     0     0     0
## important        1     1     1     1     1     1     0     1     1     0     1
## continue         1     1     1     1     1     1     1     1     1     1     1
## support          1     1     1     1     1     1     1     1     1     1     0
## protect          1     1     1     1     1     1     0     1     1     1     1
## people           1     1     1     1     1     1     0     1     1     1     1
## threat           0     0     0     1     0     1     0     1     1     0     0
## longer           0     0     0     1     0     0     0     1     0     0     0
## imminent         0     0     0     0     0     0     0     0     0     0     0
## urllink          1     1     1     1     1     1     1     1     1     1     1
## live             1     1     1     1     1     1     1     1     1     1     1
## governor         0     1     1     1     0     1     0     1     1     0     0
## provide          1     1     1     1     1     1     0     1     1     1     1
## update           1     1     1     1     1     1     1     1     1     1     1
## media            0     1     1     1     0     0     1     0     1     0     0
## hold             1     1     0     1     1     1     0     1     1     0     0
## news             0     1     1     1     1     1     1     1     1     1     1
## conference       1     1     0     1     1     1     0     1     1     1     1
## X1.30            1     1     1     0     0     0     0     1     0     0     1
## pm               0     0     1     0     0     1     1     1     1     1     1
## today            1     1     1     1     1     1     1     1     1     1     1
## response         1     1     1     1     1     1     1     1     1     1     1
## watch            1     1     1     1     1     1     0     1     1     1     1
## faith            0     1     0     0     0     0     0     1     1     0     0
## community        1     1     1     1     1     1     0     1     1     1     1
## effort           1     1     1     1     1     1     0     1     0     1     1
## fight            1     1     1     1     0     1     0     1     1     1     0
## in.person        0     0     1     0     1     1     0     0     0     0     0
## fellowship       0     0     0     0     0     0     0     0     0     0     0
## church           0     0     0     0     0     0     0     0     1     0     0
## meet             0     0     0     1     1     1     0     1     1     0     1
## remotely         0     1     0     0     0     0     0     0     0     0     0
## present          0     0     1     0     0     1     0     0     0     0     0
## guidance         1     1     1     1     1     1     0     1     1     0     1
## give             1     1     1     1     1     1     0     1     1     0     0
## house            0     0     0     1     1     1     0     1     0     0     0
## worship          1     0     0     1     0     1     0     0     1     0     0
## option           1     0     0     0     0     0     0     0     0     0     0
## congregation     0     0     0     0     0     0     0     0     1     0     0
## thank            1     1     1     1     1     1     0     1     1     1     1
## X.walmart        0     0     0     0     0     0     0     0     1     0     0
## quest            0     0     0     0     0     0     0     0     0     0     0
## diagnostic       0     0     0     0     0     0     0     0     0     0     0
## opening          0     0     0     1     0     0     0     1     0     1     0
## drive.thru       1     0     0     1     0     0     0     1     1     1     0
## test             1     1     1     1     1     1     1     1     0     1     1
## site             0     1     1     1     1     1     0     1     0     1     1
## central          0     0     0     0     0     0     0     1     0     0     0
##              [,24] [,25] [,26] [,27] [,28] [,29] [,30] [,31] [,32] [,33] [,34]
## industry         1     1     1     1     1     0     0     0     0     1     0
## sector           0     1     0     1     1     0     1     0     0     1     1
## affect           1     1     1     0     1     1     1     0     1     1     0
## crisis           1     1     1     1     1     1     1     0     0     1     1
## important        1     1     1     1     1     1     1     1     0     1     1
## continue         1     1     1     1     1     1     1     1     1     1     1
## support          1     1     1     1     1     1     1     1     1     1     1
## protect          1     1     1     1     1     1     1     1     0     1     1
## people           1     1     1     1     1     1     1     1     0     1     1
## threat           0     1     1     1     1     1     1     0     0     1     0
## longer           0     0     1     1     1     0     0     0     0     0     0
## imminent         0     0     0     0     0     1     0     0     0     0     0
## urllink          1     1     1     1     1     1     1     1     1     1     1
## live             1     1     1     1     1     1     1     1     1     1     1
## governor         1     1     0     0     1     1     1     1     0     1     0
## provide          1     1     1     1     1     1     1     1     1     1     1
## update           1     1     1     1     1     1     1     1     1     1     1
## media            1     1     0     0     1     1     0     0     0     0     0
## hold             1     1     1     1     1     1     1     0     1     0     1
## news             1     1     1     1     1     1     1     1     0     1     0
## conference       1     1     0     0     1     1     1     0     1     1     1
## X1.30            0     0     0     0     0     0     1     0     1     1     1
## pm               1     1     1     0     1     1     1     0     0     1     1
## today            1     1     1     1     1     1     1     1     1     1     1
## response         1     1     1     1     1     1     1     1     1     1     1
## watch            1     1     0     0     1     1     1     0     0     1     1
## faith            0     1     0     0     0     1     0     0     0     1     0
## community        1     1     1     1     1     1     1     1     1     1     1
## effort           1     1     0     0     1     1     1     1     1     0     1
## fight            1     1     1     1     1     0     1     1     1     1     1
## in.person        1     0     0     0     1     0     0     0     0     0     1
## fellowship       0     0     0     0     0     0     0     0     0     0     0
## church           0     0     0     1     0     0     0     0     0     0     0
## meet             1     1     1     0     1     0     0     1     0     1     0
## remotely         0     0     0     0     1     0     0     0     0     0     0
## present          0     0     0     1     1     0     1     0     0     0     0
## guidance         1     1     0     1     1     1     1     0     0     1     1
## give             1     1     1     1     1     1     1     1     1     1     0
## house            1     1     0     1     1     0     1     1     0     1     1
## worship          0     0     0     0     0     0     0     0     0     1     0
## option           0     1     0     0     1     0     0     0     0     0     0
## congregation     0     0     0     1     0     0     0     0     0     0     0
## thank            1     1     1     1     1     1     1     1     1     1     1
## X.walmart        0     0     0     0     0     0     0     0     0     0     0
## quest            0     0     0     0     1     0     0     0     0     0     0
## diagnostic       0     0     0     0     1     0     0     0     0     0     0
## opening          1     0     0     0     1     0     1     0     1     0     0
## drive.thru       0     1     0     0     0     0     0     0     0     1     0
## test             1     1     1     1     1     1     1     1     1     1     1
## site             1     1     1     1     0     0     1     0     0     1     1
## central          0     0     1     0     0     0     0     0     0     1     0
##              [,35] [,36] [,37] [,38] [,39] [,40] [,41] [,42] [,43] [,44] [,45]
## industry         0     0     0     0     0     1     0     0     0     1     0
## sector           0     0     0     0     0     1     0     0     0     0     0
## affect           0     0     1     1     1     1     0     1     0     1     0
## crisis           0     1     1     1     1     1     1     1     1     1     1
## important        0     1     0     1     1     1     1     1     1     1     0
## continue         1     1     1     1     1     1     1     1     1     1     1
## support          0     1     1     1     1     1     0     1     1     1     1
## protect          1     1     1     1     1     1     1     1     1     1     0
## people           0     1     1     1     1     1     1     1     1     0     0
## threat           0     1     0     0     1     0     0     1     0     1     0
## longer           0     0     0     0     0     0     0     0     0     0     0
## imminent         0     0     0     0     1     0     0     0     0     0     0
## urllink          1     1     1     1     1     1     1     1     1     1     1
## live             0     1     1     1     1     1     1     1     1     1     1
## governor         0     1     1     1     1     1     0     1     0     0     1
## provide          0     1     1     1     1     1     1     1     1     1     1
## update           0     1     1     1     1     1     1     1     1     1     1
## media            0     0     0     0     1     1     1     1     0     0     1
## hold             0     0     0     0     1     1     1     1     0     0     0
## news             0     1     1     0     1     1     1     1     1     1     1
## conference       0     1     1     0     1     1     1     1     0     0     0
## X1.30            0     0     1     0     0     0     1     0     0     0     0
## pm               0     0     1     0     1     1     1     1     1     1     0
## today            1     1     1     1     1     1     1     1     1     1     0
## response         0     1     1     0     1     1     1     1     1     1     1
## watch            0     0     1     1     1     1     1     1     1     1     0
## faith            0     0     0     0     1     1     0     0     0     0     0
## community        1     1     1     1     1     1     1     1     1     1     1
## effort           0     1     1     1     1     1     1     1     1     1     1
## fight            0     1     1     0     1     1     1     1     1     1     1
## in.person        0     1     0     1     0     1     0     0     0     0     0
## fellowship       0     0     0     0     0     0     0     1     0     0     0
## church           0     0     0     0     1     1     0     0     0     0     0
## meet             0     1     1     1     0     1     0     1     0     0     0
## remotely         0     0     0     0     0     0     0     0     0     0     0
## present          0     0     0     0     0     0     0     0     0     0     0
## guidance         0     1     0     1     0     1     0     1     0     1     0
## give             0     1     1     0     1     1     1     1     1     1     0
## house            0     1     1     1     0     1     0     1     0     0     0
## worship          0     0     0     0     0     0     0     0     0     0     0
## option           0     0     0     0     1     0     0     0     1     0     0
## congregation     0     1     0     0     0     0     0     0     0     0     0
## thank            1     1     1     1     1     1     1     1     1     1     1
## X.walmart        0     0     0     0     1     0     0     0     0     0     0
## quest            0     0     0     0     0     0     0     0     0     0     0
## diagnostic       0     0     0     1     0     1     0     0     0     0     0
## opening          0     0     0     1     1     0     0     1     1     0     0
## drive.thru       0     0     0     0     1     0     0     0     0     0     0
## test             0     1     1     1     1     1     1     1     1     1     0
## site             0     0     0     1     1     0     0     0     1     1     1
## central          0     0     0     0     0     0     0     1     0     0     0
##              [,46] [,47] [,48] [,49]
## industry         0     0     1     0
## sector           0     0     1     0
## affect           1     1     1     0
## crisis           1     1     1     1
## important        1     1     1     1
## continue         1     1     1     1
## support          1     1     1     1
## protect          1     1     1     1
## people           1     1     1     1
## threat           1     0     1     0
## longer           0     0     0     0
## imminent         0     0     0     0
## urllink          1     1     1     1
## live             1     1     1     1
## governor         1     0     1     0
## provide          1     1     1     1
## update           1     1     1     1
## media            1     0     0     0
## hold             1     1     1     0
## news             1     0     1     1
## conference       1     1     1     0
## X1.30            0     0     0     0
## pm               0     0     1     1
## today            1     1     1     1
## response         1     1     1     1
## watch            1     1     1     1
## faith            0     1     1     0
## community        1     1     1     1
## effort           1     1     1     1
## fight            1     1     1     1
## in.person        0     0     1     1
## fellowship       0     0     0     0
## church           0     0     0     0
## meet             0     0     1     1
## remotely         0     1     0     1
## present          0     0     0     0
## guidance         1     1     1     1
## give             0     0     1     1
## house            1     1     1     1
## worship          0     0     0     0
## option           0     0     1     1
## congregation     0     0     0     0
## thank            1     1     1     1
## X.walmart        0     0     0     0
## quest            0     0     1     1
## diagnostic       0     0     1     0
## opening          0     0     1     0
## drive.thru       0     0     0     1
## test             1     1     1     1
## site             0     1     1     1
## central          1     0     1     0

Create Distances

While the data set includes popular distance measures, we still need to figure out how these distance measures are related to each other. Create distance measures in Euclidean or Manhattan distance.

euclidean_distance = dist(df, method="euclidean")
euclidean_distance
##              industry   sector   affect   crisis important continue  support
## sector       3.464102                                                       
## affect       4.472136 5.099020                                              
## crisis       4.898979 5.099020 3.464102                                     
## important    4.795832 5.196152 3.872983 3.605551                            
## continue     5.567764 5.567764 4.123106 3.605551  2.828427                  
## support      5.196152 5.385165 3.316625 3.000000  3.162278 2.449490         
## protect      5.291503 5.291503 4.000000 3.741657  2.236068 1.732051 3.000000
## people       5.291503 5.099020 4.000000 3.741657  2.236068 2.236068 3.000000
## threat       4.358899 4.358899 4.123106 4.358899  4.690416 5.291503 4.690416
## longer       3.605551 3.872983 5.196152 5.385165  5.830952 6.480741 6.000000
## imminent     4.242641 4.472136 5.291503 5.656854  6.082763 6.708204 6.244998
## urllink      5.567764 5.567764 4.123106 3.605551  2.828427 0.000000 2.449490
## live         5.477226 5.477226 4.000000 3.464102  2.645751 1.000000 2.236068
## governor     4.898979 4.690416 3.464102 4.000000  4.123106 4.358899 3.872983
## provide      5.477226 5.477226 3.741657 3.464102  2.645751 1.732051 2.236068
## update       5.291503 5.291503 4.000000 3.162278  3.000000 1.732051 2.236068
## media        4.690416 4.898979 4.690416 4.690416  5.000000 5.385165 5.196152
## hold         4.795832 4.358899 3.605551 4.123106  4.000000 4.472136 4.242641
## news         5.291503 5.291503 4.472136 3.464102  3.872983 3.316625 3.605551
## conference   5.099020 4.690416 3.464102 4.000000  4.123106 4.123106 3.872983
## X1.30        4.582576 4.123106 5.000000 5.196152  5.656854 6.000000 5.830952
## pm           4.690416 4.690416 4.472136 4.000000  4.582576 4.358899 4.358899
## today        5.567764 5.567764 3.872983 3.605551  2.828427 1.414214 2.828427
## response     5.567764 5.567764 3.872983 3.316625  3.162278 2.000000 2.449490
## watch        5.291503 5.099020 3.464102 3.464102  3.316625 3.316625 3.605551
## faith        3.872983 3.872983 4.582576 5.196152  5.291503 6.000000 5.477226
## community    5.477226 5.477226 4.000000 3.741657  2.645751 1.000000 2.645751
## effort       5.656854 5.656854 3.741657 3.741657  3.316625 2.645751 3.000000
## fight        4.795832 5.000000 4.123106 3.605551  3.162278 2.828427 2.828427
## in.person    4.472136 4.690416 4.898979 5.099020  5.196152 5.916080 5.385165
## fellowship   4.123106 4.358899 5.385165 5.744563  6.164414 6.782330 6.324555
## church       4.242641 4.000000 5.477226 5.830952  5.916080 6.557439 6.082763
## meet         4.242641 4.472136 4.242641 4.690416  4.123106 4.582576 4.358899
## remotely     4.472136 4.242641 5.477226 5.656854  5.916080 6.557439 6.244998
## present      4.123106 4.123106 5.000000 5.567764  5.656854 6.324555 5.830952
## guidance     4.582576 4.582576 3.605551 3.605551  2.828427 3.741657 3.464102
## give         4.472136 4.898979 3.741657 3.741657  3.316625 3.605551 3.605551
## house        4.472136 4.690416 4.000000 4.242641  3.605551 4.358899 4.123106
## worship      4.242641 4.472136 4.898979 5.656854  5.744563 6.244998 5.744563
## option       4.000000 4.690416 4.898979 5.477226  5.385165 6.082763 5.567764
## congregation 4.242641 4.000000 5.830952 5.830952  6.082763 6.708204 6.244998
## thank        5.567764 5.567764 3.872983 3.605551  2.828427 1.414214 2.449490
## X.walmart    4.358899 4.123106 5.567764 5.916080  6.164414 6.782330 6.324555
## quest        4.000000 4.000000 5.477226 5.656854  6.082763 6.708204 6.244998
## diagnostic   3.872983 3.872983 5.196152 5.567764  6.000000 6.633250 6.164414
## opening      4.358899 4.795832 4.358899 5.196152  5.291503 5.656854 5.099020
## drive.thru   4.123106 4.123106 5.196152 5.385165  5.656854 6.164414 5.656854
## test         5.291503 5.477226 3.741657 3.464102  2.645751 1.732051 2.645751
## site         4.690416 4.690416 4.472136 4.242641  4.123106 4.123106 4.123106
## central      3.872983 4.123106 5.000000 5.385165  5.830952 6.480741 6.000000
##               protect   people   threat   longer imminent  urllink     live
## sector                                                                     
## affect                                                                     
## crisis                                                                     
## important                                                                  
## continue                                                                   
## support                                                                    
## protect                                                                    
## people       1.414214                                                      
## threat       5.000000 5.000000                                             
## longer       6.244998 6.082763 4.000000                                    
## imminent     6.480741 6.324555 4.123106 3.000000                           
## urllink      1.732051 2.236068 5.291503 6.480741 6.708204                  
## live         2.000000 2.000000 5.196152 6.403124 6.633250 1.000000         
## governor     4.242641 4.000000 3.872983 5.196152 5.099020 4.358899 4.242641
## provide      2.000000 2.000000 5.000000 6.244998 6.480741 1.732051 1.414214
## update       2.449490 2.449490 5.000000 6.244998 6.480741 1.732051 1.414214
## media        5.477226 5.291503 4.582576 4.582576 4.000000 5.385165 5.291503
## hold         4.358899 4.123106 4.242641 4.690416 5.196152 4.472136 4.358899
## news         3.464102 3.464102 4.358899 5.744563 5.830952 3.316625 3.162278
## conference   4.000000 3.741657 4.582576 5.385165 5.477226 4.123106 4.000000
## X1.30        5.916080 5.744563 5.099020 3.741657 3.872983 6.000000 5.916080
## pm           4.242641 4.242641 4.358899 5.196152 5.099020 4.358899 4.242641
## today        1.732051 2.236068 5.099020 6.324555 6.557439 1.414214 1.732051
## response     2.645751 2.645751 4.898979 6.164414 6.403124 2.000000 1.732051
## watch        2.828427 2.828427 5.000000 5.916080 5.830952 3.316625 3.162278
## faith        5.744563 5.567764 4.000000 4.000000 3.000000 6.000000 5.916080
## community    1.414214 2.000000 5.196152 6.403124 6.633250 1.000000 1.414214
## effort       2.828427 2.828427 5.385165 6.244998 6.164414 2.645751 2.449490
## fight        3.000000 3.000000 4.898979 5.830952 6.244998 2.828427 2.645751
## in.person    5.656854 5.477226 4.795832 4.123106 4.000000 5.916080 5.830952
## fellowship   6.557439 6.403124 4.242641 2.828427 1.732051 6.782330 6.708204
## church       6.324555 6.164414 4.123106 3.000000 2.449490 6.557439 6.480741
## meet         4.242641 4.000000 4.358899 4.795832 5.291503 4.582576 4.472136
## remotely     6.324555 6.164414 4.795832 3.000000 2.828427 6.557439 6.480741
## present      6.082763 5.916080 4.472136 3.162278 3.316625 6.324555 6.244998
## guidance     3.316625 3.316625 4.242641 5.477226 5.744563 3.741657 3.605551
## give         3.464102 3.464102 4.358899 5.385165 5.656854 3.605551 3.464102
## house        4.000000 3.741657 4.582576 5.000000 5.477226 4.358899 4.242641
## worship      6.000000 5.830952 3.872983 3.605551 3.162278 6.244998 6.164414
## option       5.830952 5.656854 4.358899 3.872983 3.162278 6.082763 6.000000
## congregation 6.480741 6.324555 4.123106 2.645751 2.449490 6.708204 6.633250
## thank        1.732051 2.236068 5.099020 6.324555 6.557439 1.414214 1.732051
## X.walmart    6.557439 6.403124 4.242641 2.828427 1.732051 6.782330 6.708204
## quest        6.480741 6.324555 4.358899 2.645751 2.449490 6.708204 6.633250
## diagnostic   6.403124 6.244998 4.472136 2.828427 2.645751 6.633250 6.557439
## opening      5.567764 5.385165 4.242641 4.000000 3.872983 5.656854 5.567764
## drive.thru   5.916080 5.744563 4.242641 3.162278 3.316625 6.164414 6.082763
## test         2.000000 2.000000 5.196152 6.244998 6.480741 1.732051 1.414214
## site         4.000000 4.000000 4.795832 5.385165 5.477226 4.123106 4.000000
## central      6.244998 6.082763 3.741657 2.828427 3.000000 6.480741 6.403124
##              governor  provide   update    media     hold     news conference
## sector                                                                       
## affect                                                                       
## crisis                                                                       
## important                                                                    
## continue                                                                     
## support                                                                      
## protect                                                                      
## people                                                                       
## threat                                                                       
## longer                                                                       
## imminent                                                                     
## urllink                                                                      
## live                                                                         
## governor                                                                     
## provide      4.000000                                                        
## update       4.242641 2.000000                                               
## media        3.741657 5.291503 5.291503                                      
## hold         4.582576 4.123106 4.358899 4.582576                             
## news         3.741657 3.162278 3.162278 4.242641 4.795832                    
## conference   4.000000 3.741657 4.000000 4.690416 3.316625 4.242641           
## X1.30        5.196152 5.744563 5.744563 5.000000 4.898979 5.744563   4.582576
## pm           4.472136 4.242641 4.000000 4.690416 4.795832 3.464102   4.242641
## today        4.358899 2.236068 2.236068 5.385165 4.242641 3.316625   3.872983
## response     4.123106 1.732051 2.236068 5.000000 4.000000 2.645751   3.605551
## watch        4.000000 2.828427 3.464102 4.690416 4.123106 3.464102   3.162278
## faith        4.358899 5.744563 5.744563 3.872983 4.690416 5.196152   4.582576
## community    4.242641 1.414214 2.000000 5.477226 4.358899 3.464102   4.000000
## effort       4.000000 2.000000 2.828427 5.099020 4.358899 3.741657   3.741657
## fight        4.123106 2.645751 3.000000 5.000000 4.472136 3.605551   3.872983
## in.person    4.690416 5.656854 5.656854 4.690416 5.000000 5.477226   5.099020
## fellowship   5.196152 6.557439 6.557439 4.123106 5.291503 5.916080   5.567764
## church       5.099020 6.324555 6.324555 4.242641 4.795832 5.830952   5.477226
## meet         4.000000 4.472136 4.472136 5.291503 4.795832 4.690416   4.472136
## remotely     5.291503 6.324555 6.480741 4.242641 5.196152 5.830952   5.477226
## present      5.000000 6.082763 6.244998 4.358899 4.898979 5.567764   5.196152
## guidance     3.605551 3.316625 3.605551 4.795832 4.242641 4.123106   3.872983
## give         4.000000 3.464102 3.162278 4.898979 3.872983 3.464102   4.242641
## house        3.741657 4.242641 4.472136 5.099020 4.358899 4.690416   4.242641
## worship      4.690416 6.000000 6.000000 4.472136 5.196152 5.656854   5.099020
## option       5.099020 5.830952 6.000000 4.472136 5.000000 5.656854   5.291503
## congregation 5.291503 6.480741 6.480741 4.472136 5.196152 5.830952   5.477226
## thank        4.123106 1.000000 2.236068 5.385165 4.242641 3.316625   3.872983
## X.walmart    5.196152 6.557439 6.557439 4.123106 5.099020 5.916080   5.385165
## quest        5.291503 6.480741 6.480741 4.472136 5.196152 5.830952   5.477226
## diagnostic   5.000000 6.403124 6.403124 4.358899 5.099020 5.916080   5.385165
## opening      4.358899 5.385165 5.385165 4.358899 4.690416 5.196152   4.795832
## drive.thru   5.000000 5.916080 5.916080 4.582576 4.898979 5.567764   4.795832
## test         4.472136 2.000000 2.000000 5.477226 4.358899 3.464102   4.000000
## site         4.898979 4.000000 3.741657 5.477226 5.000000 4.242641   5.099020
## central      5.000000 6.244998 6.244998 4.582576 4.898979 5.567764   5.196152
##                 X1.30       pm    today response    watch    faith community
## sector                                                                      
## affect                                                                      
## crisis                                                                      
## important                                                                   
## continue                                                                    
## support                                                                     
## protect                                                                     
## people                                                                      
## threat                                                                      
## longer                                                                      
## imminent                                                                    
## urllink                                                                     
## live                                                                        
## governor                                                                    
## provide                                                                     
## update                                                                      
## media                                                                       
## hold                                                                        
## news                                                                        
## conference                                                                  
## X1.30                                                                       
## pm           4.795832                                                       
## today        5.830952 4.123106                                              
## response     5.656854 3.872983 2.000000                                     
## watch        5.196152 3.464102 3.000000 3.000000                            
## faith        4.242641 4.582576 5.830952 5.656854 5.000000                   
## community    5.916080 4.472136 1.732051 2.236068 3.162278 5.916080          
## effort       5.567764 4.472136 3.000000 2.645751 2.828427 5.744563  2.449490
## fight        5.477226 4.358899 3.162278 2.828427 3.605551 5.477226  2.645751
## in.person    4.582576 4.898979 5.744563 5.744563 5.291503 4.358899  5.830952
## fellowship   3.741657 5.196152 6.633250 6.480741 5.916080 3.464102  6.708204
## church       4.123106 5.291503 6.403124 6.244998 6.000000 3.316625  6.480741
## meet         5.385165 4.690416 4.582576 4.795832 4.690416 5.000000  4.472136
## remotely     3.872983 5.477226 6.403124 6.244998 5.656854 3.605551  6.480741
## present      4.000000 5.196152 6.164414 6.000000 5.567764 4.242641  6.244998
## guidance     5.291503 4.582576 3.741657 3.741657 3.316625 4.898979  3.605551
## give         5.196152 4.000000 3.316625 3.316625 4.000000 5.000000  3.464102
## house        5.385165 5.099020 4.123106 4.358899 4.242641 5.000000  4.242641
## worship      4.123106 5.099020 6.082763 5.916080 5.477226 3.605551  6.164414
## option       4.582576 4.898979 5.916080 5.744563 5.291503 3.605551  6.000000
## congregation 3.872983 5.477226 6.557439 6.403124 6.164414 3.605551  6.633250
## thank        5.830952 4.358899 2.000000 2.000000 3.000000 5.830952  1.000000
## X.walmart    3.741657 5.196152 6.633250 6.480741 5.916080 3.162278  6.708204
## quest        3.872983 5.099020 6.557439 6.403124 5.830952 3.605551  6.633250
## diagnostic   4.000000 5.196152 6.480741 6.480741 5.744563 3.464102  6.557439
## opening      4.690416 4.795832 5.477226 5.477226 5.000000 4.242641  5.567764
## drive.thru   3.741657 4.795832 6.000000 5.830952 5.196152 3.464102  6.082763
## test         5.744563 4.242641 1.732051 2.236068 3.162278 5.916080  2.000000
## site         5.385165 4.472136 4.358899 4.358899 4.242641 5.000000  4.000000
## central      3.741657 5.000000 6.324555 6.164414 5.744563 3.464102  6.403124
##                effort    fight in.person fellowship   church     meet remotely
## sector                                                                        
## affect                                                                        
## crisis                                                                        
## important                                                                     
## continue                                                                      
## support                                                                       
## protect                                                                       
## people                                                                        
## threat                                                                        
## longer                                                                        
## imminent                                                                      
## urllink                                                                       
## live                                                                          
## governor                                                                      
## provide                                                                       
## update                                                                        
## media                                                                         
## hold                                                                          
## news                                                                          
## conference                                                                    
## X1.30                                                                         
## pm                                                                            
## today                                                                         
## response                                                                      
## watch                                                                         
## faith                                                                         
## community                                                                     
## effort                                                                        
## fight        3.316625                                                         
## in.person    5.291503 5.744563                                                
## fellowship   6.244998 6.164414  3.872983                                      
## church       6.324555 6.082763  3.741657   2.645751                           
## meet         4.690416 4.582576  4.472136   5.000000 5.099020                  
## remotely     6.000000 5.916080  3.741657   2.645751 3.162278 5.291503         
## present      5.916080 5.656854  3.605551   3.162278 3.316625 5.196152 3.316625
## guidance     3.605551 4.000000  4.582576   5.656854 5.567764 4.123106 5.385165
## give         4.000000 3.605551  5.099020   5.744563 5.477226 4.242641 5.830952
## house        4.242641 4.123106  4.242641   5.196152 5.291503 3.464102 5.099020
## worship      6.000000 5.744563  4.000000   3.000000 3.162278 4.690416 3.741657
## option       5.477226 5.567764  3.741657   3.316625 3.464102 4.898979 3.464102
## congregation 6.480741 6.082763  3.741657   2.236068 2.000000 5.099020 2.828427
## thank        2.236068 2.828427  5.744563   6.633250 6.403124 4.582576 6.403124
## X.walmart    6.403124 6.164414  3.872983   2.000000 1.732051 5.196152 2.645751
## quest        6.164414 6.082763  3.162278   2.236068 2.828427 4.898979 2.000000
## diagnostic   6.082763 6.164414  3.000000   2.449490 2.645751 4.795832 2.645751
## opening      5.000000 5.291503  4.123106   3.741657 4.123106 4.795832 4.358899
## drive.thru   5.916080 5.477226  4.582576   3.464102 3.316625 4.795832 3.605551
## test         2.449490 3.000000  5.656854   6.557439 6.480741 4.472136 6.324555
## site         4.242641 4.358899  4.898979   5.567764 5.477226 4.690416 5.477226
## central      6.244998 5.830952  4.123106   2.449490 3.316625 4.795832 3.316625
##               present guidance     give    house  worship   option congregation
## sector                                                                         
## affect                                                                         
## crisis                                                                         
## important                                                                      
## continue                                                                       
## support                                                                        
## protect                                                                        
## people                                                                         
## threat                                                                         
## longer                                                                         
## imminent                                                                       
## urllink                                                                        
## live                                                                           
## governor                                                                       
## provide                                                                        
## update                                                                         
## media                                                                          
## hold                                                                           
## news                                                                           
## conference                                                                     
## X1.30                                                                          
## pm                                                                             
## today                                                                          
## response                                                                       
## watch                                                                          
## faith                                                                          
## community                                                                      
## effort                                                                         
## fight                                                                          
## in.person                                                                      
## fellowship                                                                     
## church                                                                         
## meet                                                                           
## remotely                                                                       
## present                                                                        
## guidance     5.291503                                                          
## give         5.385165 4.123106                                                 
## house        4.795832 3.605551 4.242641                                        
## worship      3.605551 5.000000 5.291503 5.099020                               
## option       3.605551 5.385165 5.099020 4.898979 3.464102                      
## congregation 3.000000 5.567764 5.656854 5.291503 3.162278 3.741657             
## thank        6.164414 3.464102 3.605551 4.358899 6.082763 5.916080     6.557439
## X.walmart    3.162278 5.830952 5.744563 5.567764 3.000000 3.316625     1.732051
## quest        3.000000 5.567764 5.656854 5.099020 3.464102 2.828427     2.449490
## diagnostic   3.162278 5.477226 5.744563 5.000000 3.605551 3.316625     2.645751
## opening      4.000000 5.099020 4.795832 4.582576 4.123106 3.605551     4.358899
## drive.thru   4.242641 5.291503 5.196152 5.196152 3.316625 3.605551     3.316625
## test         6.082763 3.605551 3.464102 4.000000 6.164414 5.830952     6.633250
## site         5.196152 4.123106 4.472136 4.690416 5.099020 5.099020     5.656854
## central      3.741657 5.477226 5.567764 5.000000 3.605551 3.872983     3.000000
##                 thank X.walmart    quest diagnostic  opening drive.thru
## sector                                                                 
## affect                                                                 
## crisis                                                                 
## important                                                              
## continue                                                               
## support                                                                
## protect                                                                
## people                                                                 
## threat                                                                 
## longer                                                                 
## imminent                                                               
## urllink                                                                
## live                                                                   
## governor                                                               
## provide                                                                
## update                                                                 
## media                                                                  
## hold                                                                   
## news                                                                   
## conference                                                             
## X1.30                                                                  
## pm                                                                     
## today                                                                  
## response                                                               
## watch                                                                  
## faith                                                                  
## community                                                              
## effort                                                                 
## fight                                                                  
## in.person                                                              
## fellowship                                                             
## church                                                                 
## meet                                                                   
## remotely                                                               
## present                                                                
## guidance                                                               
## give                                                                   
## house                                                                  
## worship                                                                
## option                                                                 
## congregation                                                           
## thank                                                                  
## X.walmart    6.633250                                                  
## quest        6.557439  2.236068                                        
## diagnostic   6.480741  2.449490 1.732051                               
## opening      5.477226  4.000000 3.872983   3.741657                    
## drive.thru   6.000000  2.828427 3.316625   3.741657 4.242641           
## test         2.236068  6.708204 6.480741   6.403124 5.385165   6.082763
## site         4.123106  5.567764 5.477226   5.567764 4.582576   5.196152
## central      6.324555  2.828427 2.645751   2.828427 4.000000   3.464102
##                  test     site
## sector                        
## affect                        
## crisis                        
## important                     
## continue                      
## support                       
## protect                       
## people                        
## threat                        
## longer                        
## imminent                      
## urllink                       
## live                          
## governor                      
## provide                       
## update                        
## media                         
## hold                          
## news                          
## conference                    
## X1.30                         
## pm                            
## today                         
## response                      
## watch                         
## faith                         
## community                     
## effort                        
## fight                         
## in.person                     
## fellowship                    
## church                        
## meet                          
## remotely                      
## present                       
## guidance                      
## give                          
## house                         
## worship                       
## option                        
## congregation                  
## thank                         
## X.walmart                     
## quest                         
## diagnostic                    
## opening                       
## drive.thru                    
## test                          
## site         4.000000         
## central      6.244998 5.385165
manhattan_distance = dist(df, method = "manhattan")
manhattan_distance
##              industry sector affect crisis important continue support protect
## sector             12                                                        
## affect             20     26                                                 
## crisis             24     26     12                                          
## important          23     27     15     13                                   
## continue           31     31     17     13         8                         
## support            27     29     11      9        10        6                
## protect            28     28     16     14         5        3       9        
## people             28     26     16     14         5        5       9       2
## threat             19     19     17     19        22       28      22      25
## longer             13     15     27     29        34       42      36      39
## imminent           18     20     28     32        37       45      39      42
## urllink            31     31     17     13         8        0       6       3
## live               30     30     16     12         7        1       5       4
## governor           24     22     12     16        17       19      15      18
## provide            30     30     14     12         7        3       5       4
## update             28     28     16     10         9        3       5       6
## media              22     24     22     22        25       29      27      30
## hold               23     19     13     17        16       20      18      19
## news               28     28     20     12        15       11      13      12
## conference         26     22     12     16        17       17      15      16
## X1.30              21     17     25     27        32       36      34      35
## pm                 22     22     20     16        21       19      19      18
## today              31     31     15     13         8        2       8       3
## response           31     31     15     11        10        4       6       7
## watch              28     26     12     12        11       11      13       8
## faith              15     15     21     27        28       36      30      33
## community          30     30     16     14         7        1       7       2
## effort             32     32     14     14        11        7       9       8
## fight              23     25     17     13        10        8       8       9
## in.person          20     22     24     26        27       35      29      32
## fellowship         17     19     29     33        38       46      40      43
## church             18     16     30     34        35       43      37      40
## meet               18     20     18     22        17       21      19      18
## remotely           20     18     30     32        35       43      39      40
## present            17     17     25     31        32       40      34      37
## guidance           21     21     13     13         8       14      12      11
## give               20     24     14     14        11       13      13      12
## house              20     22     16     18        13       19      17      16
## worship            18     20     24     32        33       39      33      36
## option             16     22     24     30        29       37      31      34
## congregation       18     16     34     34        37       45      39      42
## thank              31     31     15     13         8        2       6       3
## X.walmart          19     17     31     35        38       46      40      43
## quest              16     16     30     32        37       45      39      42
## diagnostic         15     15     27     31        36       44      38      41
## opening            19     23     19     27        28       32      26      31
## drive.thru         17     17     27     29        32       38      32      35
## test               28     30     14     12         7        3       7       4
## site               22     22     20     18        17       17      17      16
## central            15     17     25     29        34       42      36      39
##              people threat longer imminent urllink live governor provide update
## sector                                                                         
## affect                                                                         
## crisis                                                                         
## important                                                                      
## continue                                                                       
## support                                                                        
## protect                                                                        
## people                                                                         
## threat           25                                                            
## longer           37     16                                                     
## imminent         40     17      9                                              
## urllink           5     28     42       45                                     
## live              4     27     41       44       1                             
## governor         16     15     27       26      19   18                        
## provide           4     25     39       42       3    2       16               
## update            6     25     39       42       3    2       18       4       
## media            28     21     21       16      29   28       14      28     28
## hold             17     18     22       27      20   19       21      17     19
## news             12     19     33       34      11   10       14      10     10
## conference       14     21     29       30      17   16       16      14     16
## X1.30            33     26     14       15      36   35       27      33     33
## pm               18     19     27       26      19   18       20      18     16
## today             5     26     40       43       2    3       19       5      5
## response          7     24     38       41       4    3       17       3      5
## watch             8     25     35       34      11   10       16       8     12
## faith            31     16     16        9      36   35       19      33     33
## community         4     27     41       44       1    2       18       2      4
## effort            8     29     39       38       7    6       16       4      8
## fight             9     24     34       39       8    7       17       7      9
## in.person        30     23     17       16      35   34       22      32     32
## fellowship       41     18      8        3      46   45       27      43     43
## church           38     17      9        6      43   42       26      40     40
## meet             16     19     23       28      21   20       16      20     20
## remotely         38     23      9        8      43   42       28      40     42
## present          35     20     10       11      40   39       25      37     39
## guidance         11     18     30       33      14   13       13      11     13
## give             12     19     29       32      13   12       16      12     10
## house            14     21     25       30      19   18       14      18     20
## worship          34     15     13       10      39   38       22      36     36
## option           32     19     15       10      37   36       26      34     36
## congregation     40     17      7        6      45   44       28      42     42
## thank             5     26     40       43       2    3       17       1      5
## X.walmart        41     18      8        3      46   45       27      43     43
## quest            40     19      7        6      45   44       28      42     42
## diagnostic       39     20      8        7      44   43       25      41     41
## opening          29     18     16       15      32   31       19      29     29
## drive.thru       33     18     10       11      38   37       25      35     35
## test              4     27     39       42       3    2       20       4      4
## site             16     23     29       30      17   16       24      16     14
## central          37     14      8        9      42   41       25      39     39
##              media hold news conference X1.30 pm today response watch faith
## sector                                                                     
## affect                                                                     
## crisis                                                                     
## important                                                                  
## continue                                                                   
## support                                                                    
## protect                                                                    
## people                                                                     
## threat                                                                     
## longer                                                                     
## imminent                                                                   
## urllink                                                                    
## live                                                                       
## governor                                                                   
## provide                                                                    
## update                                                                     
## media                                                                      
## hold            21                                                         
## news            18   23                                                    
## conference      22   11   18                                               
## X1.30           25   24   33         21                                    
## pm              22   23   12         18    23                              
## today           29   18   11         15    34 17                           
## response        25   16    7         13    32 15     4                     
## watch           22   17   12         10    27 12     9        9            
## faith           15   22   27         21    18 21    34       32    25      
## community       30   19   12         16    35 20     3        5    10    35
## effort          26   19   14         14    31 20     9        7     8    33
## fight           25   20   13         15    30 19    10        8    13    30
## in.person       22   25   30         26    21 24    33       33    28    19
## fellowship      17   28   35         31    14 27    44       42    35    12
## church          18   23   34         30    17 28    41       39    36    11
## meet            28   23   22         20    29 22    21       23    22    25
## remotely        18   27   34         30    15 30    41       39    32    13
## present         19   24   31         27    16 27    38       36    31    18
## guidance        23   18   17         15    28 21    14       14    11    24
## give            24   15   12         18    27 16    11       11    16    25
## house           26   19   22         18    29 26    17       19    18    25
## worship         20   27   32         26    17 26    37       35    30    13
## option          20   25   32         28    21 24    35       33    28    13
## congregation    20   27   34         30    15 30    43       41    38    13
## thank           29   18   11         15    34 19     4        4     9    34
## X.walmart       17   26   35         29    14 27    44       42    35    10
## quest           20   27   34         30    15 26    43       41    34    13
## diagnostic      19   26   35         29    16 27    42       42    33    12
## opening         19   22   27         23    22 23    30       30    25    18
## drive.thru      21   24   31         23    14 23    36       34    27    12
## test            30   19   12         16    33 18     3        5    10    35
## site            30   25   18         26    29 20    19       19    18    25
## central         21   24   31         27    14 25    40       38    33    12
##              community effort fight in.person fellowship church meet remotely
## sector                                                                       
## affect                                                                       
## crisis                                                                       
## important                                                                    
## continue                                                                     
## support                                                                      
## protect                                                                      
## people                                                                       
## threat                                                                       
## longer                                                                       
## imminent                                                                     
## urllink                                                                      
## live                                                                         
## governor                                                                     
## provide                                                                      
## update                                                                       
## media                                                                        
## hold                                                                         
## news                                                                         
## conference                                                                   
## X1.30                                                                        
## pm                                                                           
## today                                                                        
## response                                                                     
## watch                                                                        
## faith                                                                        
## community                                                                    
## effort               6                                                       
## fight                7     11                                                
## in.person           34     28    33                                          
## fellowship          45     39    38        15                                
## church              42     40    37        14          7                     
## meet                20     22    21        20         25     26              
## remotely            42     36    35        14          7     10   28         
## present             39     35    32        13         10     11   27       11
## guidance            13     13    16        21         32     31   17       29
## give                12     16    13        26         33     30   18       34
## house               18     18    17        18         27     28   12       26
## worship             38     36    33        16          9     10   22       14
## option              36     30    31        14         11     12   24       12
## congregation        44     42    37        14          5      4   26        8
## thank                1      5     8        33         44     41   21       41
## X.walmart           45     41    38        15          4      3   27        7
## quest               44     38    37        10          5      8   24        4
## diagnostic          43     37    38         9          6      7   23        7
## opening             31     25    28        17         14     17   23       19
## drive.thru          37     35    30        21         12     11   23       13
## test                 4      6     9        32         43     42   20       40
## site                16     18    19        24         31     30   22       30
## central             41     39    34        17          6     11   23       11
##              present guidance give house worship option congregation thank
## sector                                                                    
## affect                                                                    
## crisis                                                                    
## important                                                                 
## continue                                                                  
## support                                                                   
## protect                                                                   
## people                                                                    
## threat                                                                    
## longer                                                                    
## imminent                                                                  
## urllink                                                                   
## live                                                                      
## governor                                                                  
## provide                                                                   
## update                                                                    
## media                                                                     
## hold                                                                      
## news                                                                      
## conference                                                                
## X1.30                                                                     
## pm                                                                        
## today                                                                     
## response                                                                  
## watch                                                                     
## faith                                                                     
## community                                                                 
## effort                                                                    
## fight                                                                     
## in.person                                                                 
## fellowship                                                                
## church                                                                    
## meet                                                                      
## remotely                                                                  
## present                                                                   
## guidance          28                                                      
## give              29       17                                             
## house             23       13   18                                        
## worship           13       25   28    26                                  
## option            13       29   26    24      12                          
## congregation       9       31   32    28      10     14                   
## thank             38       12   13    19      37     35           43      
## X.walmart         10       34   33    31       9     11            3    44
## quest              9       31   32    26      12      8            6    43
## diagnostic        10       30   33    25      13     11            7    42
## opening           16       26   23    21      17     13           19    30
## drive.thru        18       28   27    27      11     13           11    36
## test              37       13   12    16      38     34           44     5
## site              27       17   20    22      26     26           32    17
## central           14       30   31    25      13     15            9    40
##              X.walmart quest diagnostic opening drive.thru test site
## sector                                                              
## affect                                                              
## crisis                                                              
## important                                                           
## continue                                                            
## support                                                             
## protect                                                             
## people                                                              
## threat                                                              
## longer                                                              
## imminent                                                            
## urllink                                                             
## live                                                                
## governor                                                            
## provide                                                             
## update                                                              
## media                                                               
## hold                                                                
## news                                                                
## conference                                                          
## X1.30                                                               
## pm                                                                  
## today                                                               
## response                                                            
## watch                                                               
## faith                                                               
## community                                                           
## effort                                                              
## fight                                                               
## in.person                                                           
## fellowship                                                          
## church                                                              
## meet                                                                
## remotely                                                            
## present                                                             
## guidance                                                            
## give                                                                
## house                                                               
## worship                                                             
## option                                                              
## congregation                                                        
## thank                                                               
## X.walmart                                                           
## quest                5                                              
## diagnostic           6     3                                        
## opening             16    15         14                             
## drive.thru           8    11         14      18                     
## test                45    42         41      29         37          
## site                31    30         31      21         27   16     
## central              8     7          8      16         12   39   29

Create Cluster

euclidean_cluster = hclust(euclidean_distance, method = "ward.D2")
plot(euclidean_cluster, hang = -1)

manhattan_cluster = hclust(manhattan_distance, method = "ward.D2")
plot(manhattan_cluster, hang = -1)

Silhouette

sapply(2:8, function(x) summary(silhouette(cutree(euclidean_cluster, k = x),euclidean_distance))$avg.width)
## [1] 0.3549810 0.2429329 0.1961248 0.1973614 0.1822022 0.1896180 0.1738718
sapply(2:8, function(x) summary(silhouette(cutree(manhattan_cluster, k = x),manhattan_distance))$avg.width)
## [1] 0.5506627 0.3932275 0.3312193 0.3173765 0.3274395 0.3186988 0.3267146

Examine those results

plot(euclidean_cluster, hang = -1)
rect.hclust(euclidean_cluster, k = 2)

plot(manhattan_cluster, hang = -1)
rect.hclust(manhattan_cluster, k = 2)

Snake Plots

Make a snake plot of the results by plotting a random subset of 25 word pairs.

random_data = df[ , sample(1:ncol(df), 25)]
clustercut = cutree(euclidean_cluster, k = 2)
cluster1 = random_data[ names(clustercut[clustercut == 1]), ]
cluster2 = random_data[ names(clustercut[clustercut == 2]), ]
differences = colMeans(cluster1) - colMeans(cluster2)

{plot(sort(differences)*1.2,
      1:length(differences),
      type = "n",
      xlab = "Cluster 2 < -- > Cluster 1",
      yaxt = "n", ylab = "")
text(sort(differences),
     1:length(differences),
     names(sort(differences)))}

Bootstrapping

pv_cluster = pvclust(df,method.hclust = "ward.D2",method.dist = "euclidean")
## Bootstrap (r = 0.49)... Done.
## Bootstrap (r = 0.59)... Done.
## Bootstrap (r = 0.69)... Done.
## Bootstrap (r = 0.78)... Done.
## Bootstrap (r = 0.88)... Done.
## Bootstrap (r = 1.0)... Done.
## Bootstrap (r = 1.1)... Done.
## Bootstrap (r = 1.2)... Done.
## Bootstrap (r = 1.29)... Done.
## Bootstrap (r = 1.39)... Done.
plot(pv_cluster, hang = -1)

cluster_labels <- rownames(gov_tweets)

Working with Python

import scipy.cluster.hierarchy as sch
import matplotlib
from sklearn.cluster import AgglomerativeClustering
from matplotlib import pyplot as plt
from sklearn import metrics
from scipy.cluster.hierarchy import fcluster
matplotlib.use('Agg')
max_d = 12
sim_data = r.gov_tweets
sim_dist = sch.linkage(sim_data, method = 'ward')
plt.figure()
plt.title("Hierarchical Clustering Dendogram")
plt.xlabel("Causal Variable")
plt.ylabel("Distance")
sch.dendrogram(sim_dist,
              leaf_rotation=90., leaf_font_size=8.,
              labels = r.cluster_labels)
## {'icoord': [[25.0, 25.0, 35.0, 35.0], [15.0, 15.0, 30.0, 30.0], [5.0, 5.0, 22.5, 22.5], [65.0, 65.0, 75.0, 75.0], [55.0, 55.0, 70.0, 70.0], [45.0, 45.0, 62.5, 62.5], [105.0, 105.0, 115.0, 115.0], [95.0, 95.0, 110.0, 110.0], [125.0, 125.0, 135.0, 135.0], [175.0, 175.0, 185.0, 185.0], [165.0, 165.0, 180.0, 180.0], [155.0, 155.0, 172.5, 172.5], [145.0, 145.0, 163.75, 163.75], [205.0, 205.0, 215.0, 215.0], [195.0, 195.0, 210.0, 210.0], [154.375, 154.375, 202.5, 202.5], [130.0, 130.0, 178.4375, 178.4375], [102.5, 102.5, 154.21875, 154.21875], [85.0, 85.0, 128.359375, 128.359375], [53.75, 53.75, 106.6796875, 106.6796875], [13.75, 13.75, 80.21484375, 80.21484375], [245.0, 245.0, 255.0, 255.0], [235.0, 235.0, 250.0, 250.0], [225.0, 225.0, 242.5, 242.5], [265.0, 265.0, 275.0, 275.0], [285.0, 285.0, 295.0, 295.0], [315.0, 315.0, 325.0, 325.0], [305.0, 305.0, 320.0, 320.0], [345.0, 345.0, 355.0, 355.0], [335.0, 335.0, 350.0, 350.0], [312.5, 312.5, 342.5, 342.5], [290.0, 290.0, 327.5, 327.5], [270.0, 270.0, 308.75, 308.75], [375.0, 375.0, 385.0, 385.0], [395.0, 395.0, 405.0, 405.0], [415.0, 415.0, 425.0, 425.0], [400.0, 400.0, 420.0, 420.0], [380.0, 380.0, 410.0, 410.0], [455.0, 455.0, 465.0, 465.0], [445.0, 445.0, 460.0, 460.0], [475.0, 475.0, 485.0, 485.0], [452.5, 452.5, 480.0, 480.0], [435.0, 435.0, 466.25, 466.25], [395.0, 395.0, 450.625, 450.625], [365.0, 365.0, 422.8125, 422.8125], [289.375, 289.375, 393.90625, 393.90625], [233.75, 233.75, 341.640625, 341.640625], [46.982421875, 46.982421875, 287.6953125, 287.6953125]], 'dcoord': [[0.0, 17.029386365926403, 17.029386365926403, 0.0], [0.0, 17.378147196982766, 17.378147196982766, 17.029386365926403], [0.0, 18.303005217723125, 18.303005217723125, 17.378147196982766], [0.0, 9.746794344808963, 9.746794344808963, 0.0], [0.0, 12.635927614016575, 12.635927614016575, 9.746794344808963], [0.0, 12.935738607954836, 12.935738607954836, 12.635927614016575], [0.0, 15.132745950421556, 15.132745950421556, 0.0], [0.0, 16.299284237863535, 16.299284237863535, 15.132745950421556], [0.0, 16.46207763315433, 16.46207763315433, 0.0], [0.0, 14.45683229480096, 14.45683229480096, 0.0], [0.0, 14.662878298615178, 14.662878298615178, 14.45683229480096], [0.0, 15.149257407543114, 15.149257407543114, 14.662878298615178], [0.0, 15.953056133543816, 15.953056133543816, 15.149257407543114], [0.0, 15.329709716755891, 15.329709716755891, 0.0], [0.0, 16.0312195418814, 16.0312195418814, 15.329709716755891], [15.953056133543816, 16.830032679706836, 16.830032679706836, 16.0312195418814], [16.46207763315433, 17.39396447047078, 17.39396447047078, 16.830032679706836], [16.299284237863535, 17.696008531550774, 17.696008531550774, 17.39396447047078], [0.0, 18.3213080774908, 18.3213080774908, 17.696008531550774], [12.935738607954836, 19.63395180528015, 19.63395180528015, 18.3213080774908], [18.303005217723125, 21.16052165632211, 21.16052165632211, 19.63395180528015], [0.0, 17.08800749063506, 17.08800749063506, 0.0], [0.0, 18.036999011291577, 18.036999011291577, 17.08800749063506], [0.0, 21.740898478827106, 21.740898478827106, 18.036999011291577], [0.0, 18.466185312619388, 18.466185312619388, 0.0], [0.0, 17.46424919657298, 17.46424919657298, 0.0], [0.0, 16.401219466856727, 16.401219466856727, 0.0], [0.0, 17.019596548292988, 17.019596548292988, 16.401219466856727], [0.0, 16.881943016134134, 16.881943016134134, 0.0], [0.0, 17.175564037317667, 17.175564037317667, 16.881943016134134], [17.019596548292988, 17.62573875520305, 17.62573875520305, 17.175564037317667], [17.46424919657298, 18.732769861039415, 18.732769861039415, 17.62573875520305], [18.466185312619388, 19.487175269905073, 19.487175269905073, 18.732769861039415], [0.0, 17.46424919657298, 17.46424919657298, 0.0], [0.0, 17.0, 17.0, 0.0], [0.0, 17.175564037317667, 17.175564037317667, 0.0], [17.0, 17.916472867168913, 17.916472867168913, 17.175564037317667], [17.46424919657298, 18.357559750685823, 18.357559750685823, 17.916472867168913], [0.0, 17.578395831246947, 17.578395831246947, 0.0], [0.0, 17.74823934929885, 17.74823934929885, 17.578395831246947], [0.0, 17.776388834631177, 17.776388834631177, 0.0], [17.74823934929885, 18.395651660107074, 18.395651660107074, 17.776388834631177], [0.0, 18.68867749913478, 18.68867749913478, 18.395651660107074], [18.357559750685823, 19.45079261452687, 19.45079261452687, 18.68867749913478], [0.0, 20.790160394541676, 20.790160394541676, 19.45079261452687], [19.487175269905073, 21.83902799606038, 21.83902799606038, 20.790160394541676], [21.740898478827106, 25.125834681419104, 25.125834681419104, 21.83902799606038], [21.16052165632211, 42.157789154817436, 42.157789154817436, 25.125834681419104]], 'ivl': ['2', '38', '11', '47', '32', '45', '19', '35', '1', '37', '22', '41', '10', '29', '31', '44', '34', '12', '23', '17', '9', '43', '4', '20', '25', '28', '6', '8', '21', '46', '39', '13', '14', '26', '15', '27', '3', '30', '42', '5', '33', '7', '36', '16', '18', '40', '49', '24', '48'], 'leaves': [1, 37, 10, 46, 31, 44, 18, 34, 0, 36, 21, 40, 9, 28, 30, 43, 33, 11, 22, 16, 8, 42, 3, 19, 24, 27, 5, 7, 20, 45, 38, 12, 13, 25, 14, 26, 2, 29, 41, 4, 32, 6, 35, 15, 17, 39, 48, 23, 47], 'color_list': ['C1', 'C1', 'C1', 'C1', 'C1', 'C1', 'C1', 'C1', 'C1', 'C1', 'C1', 'C1', 'C1', 'C1', 'C1', 'C1', 'C1', 'C1', 'C1', 'C1', 'C1', 'C2', 'C2', 'C2', 'C2', 'C2', 'C2', 'C2', 'C2', 'C2', 'C2', 'C2', 'C2', 'C2', 'C2', 'C2', 'C2', 'C2', 'C2', 'C2', 'C2', 'C2', 'C2', 'C2', 'C2', 'C2', 'C2', 'C0']}
plt.show()

for i in range(2, max_d):
  sil = metrics.silhouette_score(sim_data, fcluster(sim_dist, i, criterion='maxclust'), metric='euclidean')
  print(i, ":", sil)
## 2 : 0.07908269749204867
## 3 : 0.06578709521762185
## 4 : 0.04594118774987207
## 5 : 0.048471531939069695
## 6 : 0.039189103960027005
## 7 : 0.04004797410109079
## 8 : 0.00725201780298204
## 9 : 0.007337152809636061
## 10 : 0.007217797727869243
## 11 : 0.007236429985985678

Interpretation