CORRELACION

corrm <- cor(cat[,3:17])
catnum <- cat[,3:17]
#write.xlsx(corrm, file = "corr.xlsx")

HIER

hh <- dist(catnum, method = "euclidean")
hc <- hclust(hh, method = "ward.D2")
hc5 <- cutree(hc, k = 5)
table(hc5)
## hc5
##   1   2   3   4   5 
## 138  93 106 166 102
cat$hc5 <- hc5

#write_xlsx(cat, "catK.xlsx")

K1 <- subset(cat, hc5 == "1")
K1[,1:2]
## # A tibble: 138 x 2
##    CIUDAD    BARRIO               
##    <chr>     <chr>                
##  1 Austin    Barton Hills         
##  2 Austin    Clarksville          
##  3 Austin    North Loop           
##  4 Austin    Old West Austin      
##  5 Austin    Travis Heights       
##  6 Austin    Zilker               
##  7 Bangkok   Din Daeng/Huai Khwang
##  8 Bangkok   Phra Khanong         
##  9 Bangkok   Thonburi             
## 10 Barcelona El Poblenou          
## # ... with 128 more rows
K2 <- subset(cat, hc5 == "2")
K2[,1:2]
## # A tibble: 93 x 2
##    CIUDAD  BARRIO                
##    <chr>   <chr>                 
##  1 Austin  Bouldin Creek         
##  2 Austin  South Lamar           
##  3 Austin  Universidad de Texas  
##  4 Bangkok Aree                  
##  5 Bangkok Bang Na               
##  6 Bangkok Chatuchak             
##  7 Bangkok Klong Toey            
##  8 Bangkok Pathum Wan            
##  9 Bangkok Ratchathewi/Phaya Thai
## 10 Bangkok Siam                  
## # ... with 83 more rows
K3 <- subset(cat, hc5 == "3")
K3[,1:2]
## # A tibble: 106 x 2
##    CIUDAD    BARRIO                         
##    <chr>     <chr>                          
##  1 Austin    Centro                         
##  2 Austin    Hancock                        
##  3 Austin    St. Edwards                    
##  4 Bangkok   Sathorn                        
##  5 Bangkok   Upper Sukhumvit                
##  6 Barcelona El Raval                       
##  7 Barcelona Gràcia                         
##  8 Barcelona L'Antiga Esquerra de l'Eixample
##  9 Barcelona Les Corts                      
## 10 Barcelona Sant Andreu                    
## # ... with 96 more rows
K4 <- subset(cat, hc5 == "4")
K4[,1:2]
## # A tibble: 166 x 2
##    CIUDAD    BARRIO                 
##    <chr>     <chr>                  
##  1 Austin    Dawson                 
##  2 Austin    East Downtown          
##  3 Austin    East Riverside         
##  4 Austin    Galindo                
##  5 Austin    South Congress         
##  6 Bangkok   Banglampoo             
##  7 Bangkok   Chinatown              
##  8 Bangkok   Monumento a la Victoria
##  9 Bangkok   Thong Lo               
## 10 Barcelona Dreta de l'Eixample    
## # ... with 156 more rows
K5 <- subset(cat, hc5 == "5")
K5[,1:2]
## # A tibble: 102 x 2
##    CIUDAD    BARRIO                        
##    <chr>     <chr>                         
##  1 Austin    Hyde Park                     
##  2 Austin    Parker Lane                   
##  3 Austin    Upper Boggy Creek             
##  4 Bangkok   Dusit                         
##  5 Barcelona La Nova Esquerra de l'Eixample
##  6 Barcelona La Vila Olímpica              
##  7 Barcelona Sant Martí                    
##  8 Berlín    Wedding                       
##  9 Boston    Back Bay                      
## 10 Boston    Beacon Hill                   
## # ... with 92 more rows
fviz_cluster(list(data = catnum, cluster = hc5))

plot(hc, cex = 0.6)
rect.hclust(hc, k = 5, border = 2:5)

df <- scale(catnum)
set.seed(123)


fviz_nbclust(df, kmeans, method = "wss")

finalK <- kmeans(df, centers = 5, nstart = 100)

fviz_cluster(finalK, data = df)

print(finalK)
## K-means clustering with 5 clusters of sizes 79, 75, 255, 158, 38
## 
## Cluster means:
##   Amenities (commercial fabric) Amenities (leisure & tourism attractions)
## 1                    -0.3732624                               -0.19764491
## 2                     0.2065275                               -0.02433894
## 3                    -0.3365329                               -0.48323000
## 4                     0.7478567                                0.98020115
## 5                    -0.4828235                               -0.37391480
##   Amenities (natural resources)       AMEN       COMM Destinations         LAND
## 1                    -0.1252825 -0.4267594  0.0425462   0.01096325  0.259183160
## 2                    -0.2356818  0.0703529 -0.2009592   0.12334850  0.607050040
## 3                    -0.2107066 -0.6177004 -0.1487582  -0.01776377 -0.136916432
## 4                    -0.2848352  1.1255266  0.4210822  -0.07708230 -0.197516673
## 5                     3.3238840  0.2136297 -0.4443911   0.17346135  0.003081627
##          NEG        PHYS         POS
## 1  2.2258904 -0.02706587  0.03655598
## 2 -0.3506826 -0.13454760 -0.10210217
## 3 -0.4084927  0.26562519 -0.08745779
## 4 -0.2438437 -0.30143171  0.22268091
## 5 -0.1802950 -0.20734050 -0.21347650
##   Territory (tangible & intangible attributes) Time / moment of the day
## 1                                   0.31113738              -0.11271150
## 2                                  -0.11534944               0.59341467
## 3                                   0.06668949              -0.14681694
## 4                                  -0.28961805              -0.04405187
## 5                                   0.33750493               0.23149007
##           URB         VERB Weather / climate conditions
## 1 -0.14946540 -0.008191888                   0.01304072
## 2  1.71529883  0.264491118                   0.97888942
## 3 -0.22812380 -0.050481722                  -0.19538969
## 4 -0.34871600 -0.076754425                  -0.12734426
## 5 -0.09397236  0.152904300                  -0.11847784
## 
## Clustering vector:
##   [1] 5 4 4 1 3 1 3 2 3 3 3 5 3 5 4 3 5 4 1 3 4 2 3 4 1 1 3 2 3 4 2 5 4 2 1 4 4
##  [38] 3 4 2 4 3 4 2 3 4 2 3 3 3 1 3 3 2 3 4 4 3 4 4 3 4 3 3 4 4 4 2 1 3 3 3 3 4
##  [75] 4 3 3 3 1 2 1 3 3 4 3 3 3 4 3 1 3 3 3 4 3 4 3 1 2 4 3 1 3 3 3 4 3 4 1 1 1
## [112] 4 3 3 4 4 4 3 3 2 2 2 3 1 3 3 3 3 3 2 2 3 1 3 5 5 3 5 5 5 5 2 3 3 4 4 1 4
## [149] 4 3 2 3 1 4 4 3 3 2 3 3 4 3 3 4 3 3 1 4 3 1 1 4 4 3 4 4 4 4 4 4 4 4 4 1 1
## [186] 3 4 1 3 2 3 3 3 4 3 3 3 4 4 1 4 4 1 2 3 2 1 4 5 3 3 3 3 3 1 2 3 4 3 3 3 2
## [223] 1 1 4 3 1 3 2 4 5 1 3 3 3 3 1 4 3 3 4 1 1 3 4 4 3 3 1 4 2 3 3 5 4 1 3 2 4
## [260] 3 2 4 3 1 4 3 2 3 1 3 4 4 4 3 4 4 5 2 5 3 2 4 5 4 5 3 4 1 3 4 4 2 3 2 3 3
## [297] 3 4 3 4 4 3 3 1 4 3 3 3 4 2 3 1 1 4 5 3 3 3 3 3 3 3 3 3 3 3 3 4 3 2 1 4 1
## [334] 4 2 4 3 2 1 4 3 4 3 3 3 1 3 3 3 4 4 3 3 3 2 4 3 4 3 4 4 1 4 3 3 5 4 1 3 4
## [371] 1 3 4 4 4 4 3 4 4 5 3 3 2 3 5 5 4 3 5 2 3 3 3 1 3 3 3 2 3 1 1 2 1 4 3 1 2
## [408] 2 3 1 3 4 2 4 3 3 3 4 3 3 4 4 3 2 4 4 4 2 3 1 3 1 1 3 3 4 1 3 3 3 3 3 3 3
## [445] 4 4 1 4 3 5 2 3 2 4 3 3 3 3 3 3 3 4 4 1 4 3 3 1 3 2 4 3 3 4 3 3 2 3 2 4 4
## [482] 2 1 4 4 3 3 3 2 2 3 3 3 4 4 3 3 2 3 3 1 4 2 2 2 4 2 5 5 4 4 3 3 4 2 3 3 3
## [519] 3 5 4 2 2 4 5 4 3 3 4 5 5 2 3 1 5 4 2 1 3 4 3 2 3 3 2 3 3 3 3 4 3 3 3 1 5
## [556] 1 3 3 3 4 4 3 4 4 4 1 3 3 4 3 5 1 5 5 5 5 2 4 1 3 1 2 4 3 2 2 3 4 2 1 3 1
## [593] 3 1 1 3 3 3 3 2 2 3 3 3 3
## 
## Within cluster sum of squares by cluster:
## [1]  924.8241 1295.3555 2424.2227 1864.8769  423.8366
##  (between_SS / total_SS =  23.5 %)
## 
## Available components:
## 
## [1] "cluster"      "centers"      "totss"        "withinss"     "tot.withinss"
## [6] "betweenss"    "size"         "iter"         "ifault"