## Map indeces and do correlations 29.09.2024 as agreed with ismir
#this document contains:
#1. enhanced maps of all indexes
#2. decomposition regression
#3. maps that represend scaled standardized index

##to do with this (10.10.)
#1. decide which version of quality of life should we take
#2. rerun graphs of QoLI with adequate name
#3. rerun regression output through chat gpt for interpretation

#Open libraries

library(ggplot2)
library(ggmap)
## ℹ Google's Terms of Service: <https://mapsplatform.google.com>
##   Stadia Maps' Terms of Service: <https://stadiamaps.com/terms-of-service/>
##   OpenStreetMap's Tile Usage Policy: <https://operations.osmfoundation.org/policies/tiles/>
## ℹ Please cite ggmap if you use it! Use `citation("ggmap")` for details.
### Maping with sf and ggplot

library(sf)
## Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.3.1; sf_use_s2() is TRUE
library(tmap)
## Breaking News: tmap 3.x is retiring. Please test v4, e.g. with
## remotes::install_github('r-tmap/tmap')
library(maps)
library(raster)
## Loading required package: sp
library(dplyr)
## 
## Attaching package: 'dplyr'
## 
## The following objects are masked from 'package:raster':
## 
##     intersect, select, union
## 
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## 
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(spData)
## To access larger datasets in this package, install the spDataLarge
## package with: `install.packages('spDataLarge',
## repos='https://nowosad.github.io/drat/', type='source')`
#library(spDataLarge) samo mi ova nije instalirana, probacu bez nje


### Import map

## Import map

amraGIS.nova <- st_read ("C:/Users/Amra/Documents/HBS database inspecting/geoBoundaries-BIH-ADM2-all/geoBoundaries-BIH-ADM2_simplified.shp")
## Reading layer `geoBoundaries-BIH-ADM2_simplified' from data source 
##   `C:\Users\Amra\Documents\HBS database inspecting\geoBoundaries-BIH-ADM2-all\geoBoundaries-BIH-ADM2_simplified.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 142 features and 5 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: 15.73111 ymin: 42.54831 xmax: 19.62407 ymax: 45.27963
## Geodetic CRS:  WGS 84
amraGIS.nova$shapeName <- c("Brcko", "Vukosavlje","Banja Luka", "Bihac", "Bijeljina", "Doboj", "Jajce", "Mostar", "Prijedor",  "Trebinje", 
                             "Zenica", "Banovici", "Berkovici" , "Bileca","Gradiska", "Kostajnica", 
                             "Bosanska Krupa" , "Kozarska Dubica", "Brod", "Novi Grad", "Bosanski Petrovac", 
                             "Samac", "Bosansko Grahovo", "Breza" , "Bugojno" , "Busovaca", "Buzim"  , "Cajnice",
                             "Capljina", "Cazin", "Celic", "Celinac", "Sarajevo - Centar", "Citluk", 
                             "Derventa", "Doboj Istok", "Doboj Jug", "Dobretici", "Domaljevac-Samac", 
                             "Donji Vakuf", "Donji Zabar", "Drvar", "Istocni Drvar", "Istocna Ilidza", 
                             "Istocni Mostar", "Istocno Novo Sarajevo", "Istocni Stari Grad", "Foca (RS)",
                             "Fojnica", "Gacko", "Glamoc","Gorazde", "Gornji Vakuf-Uskoplje", "Gracanica", 
                             "Gradacac", "Grude", "Hadzici", "Han Pijesak", "Ilidza", "Ilijas", "Jablanica",
                             "Jezero", "Kakanj", "Kalesija", "Kalinovik", "Kiseljak", "Kladanj", "Kljuc", 
                             "Konjic", "Kotor Varos", "Kresevo", "Krupa na Uni", "Kupres (RS)", 
                             "Kupres (FBiH)", "Laktasi", "Livno", "Ljubinje", "Ljubuski", "Lopare", "Lukavac", 
                             "Maglaj", "Milici", "Modrica", "Mrkonjic Grad" ,"Neum", "Nevesinje", "Novo Gorazde",
                             "Sarajevo - Novo Sarajevo", "Sarajevo - Novi Grad", "Novi Travnik", "Odzak", 
                             "Sarajevo - Stari Grad", "Olovo", "Orasje", "Osmaci", "Ostra Luka", "Pale (RS)",
                             "Pale (FBiH)", "Pelagicevo", "Petrovac", "Petrovo", "Posusje", "Prnjavor", 
                             "Prozor-Rama", "Ravno", "Ribnik", "Rogatica", "Rudo", "Sanski Most", "Sapna",
                             "Sekovici", "Sipovo", "Siroki Brijeg", "Knezevo", "Sokolac", "Srbac", "Srebrenica",
                             "Srebrenik", "Stolac", "Teocak", "Tesanj", "Teslic", "Tomislavgrad", "Travnik",
                             "Trnovo (FBiH)", "Tuzla", "Ugljevik", "Usora", "Foca (FBiH)", "Vares",
                             "Velika Kladusa", "Visegrad", "Visoko", "Vitez", "Vlasenica", "Vogosca", 
                             "Zavidovici", "Zepce", "Zivinice", "Zvornik", "Bratunac", "Trnovo (RS)")
table(amraGIS.nova$shapeName)
## 
##                 Banovici               Banja Luka                Berkovici 
##                        1                        1                        1 
##                    Bihac                Bijeljina                   Bileca 
##                        1                        1                        1 
##           Bosanska Krupa        Bosanski Petrovac         Bosansko Grahovo 
##                        1                        1                        1 
##                 Bratunac                    Brcko                    Breza 
##                        1                        1                        1 
##                     Brod                  Bugojno                 Busovaca 
##                        1                        1                        1 
##                    Buzim                  Cajnice                 Capljina 
##                        1                        1                        1 
##                    Cazin                    Celic                  Celinac 
##                        1                        1                        1 
##                   Citluk                 Derventa                    Doboj 
##                        1                        1                        1 
##              Doboj Istok                Doboj Jug                Dobretici 
##                        1                        1                        1 
##         Domaljevac-Samac              Donji Vakuf              Donji Zabar 
##                        1                        1                        1 
##                    Drvar              Foca (FBiH)                Foca (RS) 
##                        1                        1                        1 
##                  Fojnica                    Gacko                   Glamoc 
##                        1                        1                        1 
##                  Gorazde    Gornji Vakuf-Uskoplje                Gracanica 
##                        1                        1                        1 
##                 Gradacac                 Gradiska                    Grude 
##                        1                        1                        1 
##                  Hadzici              Han Pijesak                   Ilidza 
##                        1                        1                        1 
##                   Ilijas           Istocna Ilidza            Istocni Drvar 
##                        1                        1                        1 
##           Istocni Mostar       Istocni Stari Grad    Istocno Novo Sarajevo 
##                        1                        1                        1 
##                Jablanica                    Jajce                   Jezero 
##                        1                        1                        1 
##                   Kakanj                 Kalesija                Kalinovik 
##                        1                        1                        1 
##                 Kiseljak                  Kladanj                    Kljuc 
##                        1                        1                        1 
##                  Knezevo                   Konjic               Kostajnica 
##                        1                        1                        1 
##              Kotor Varos          Kozarska Dubica                  Kresevo 
##                        1                        1                        1 
##             Krupa na Uni            Kupres (FBiH)              Kupres (RS) 
##                        1                        1                        1 
##                  Laktasi                    Livno                   Lopare 
##                        1                        1                        1 
##                  Lukavac                 Ljubinje                 Ljubuski 
##                        1                        1                        1 
##                   Maglaj                   Milici                  Modrica 
##                        1                        1                        1 
##                   Mostar            Mrkonjic Grad                     Neum 
##                        1                        1                        1 
##                Nevesinje                Novi Grad             Novi Travnik 
##                        1                        1                        1 
##             Novo Gorazde                    Odzak                    Olovo 
##                        1                        1                        1 
##                   Orasje                   Osmaci               Ostra Luka 
##                        1                        1                        1 
##              Pale (FBiH)                Pale (RS)               Pelagicevo 
##                        1                        1                        1 
##                 Petrovac                  Petrovo                  Posusje 
##                        1                        1                        1 
##                 Prijedor                 Prnjavor              Prozor-Rama 
##                        1                        1                        1 
##                    Ravno                   Ribnik                 Rogatica 
##                        1                        1                        1 
##                     Rudo                    Samac              Sanski Most 
##                        1                        1                        1 
##                    Sapna        Sarajevo - Centar     Sarajevo - Novi Grad 
##                        1                        1                        1 
## Sarajevo - Novo Sarajevo    Sarajevo - Stari Grad                 Sekovici 
##                        1                        1                        1 
##                   Sipovo            Siroki Brijeg                  Sokolac 
##                        1                        1                        1 
##                    Srbac               Srebrenica                Srebrenik 
##                        1                        1                        1 
##                   Stolac                   Teocak                   Tesanj 
##                        1                        1                        1 
##                   Teslic             Tomislavgrad                  Travnik 
##                        1                        1                        1 
##                 Trebinje            Trnovo (FBiH)              Trnovo (RS) 
##                        1                        1                        1 
##                    Tuzla                 Ugljevik                    Usora 
##                        1                        1                        1 
##                    Vares           Velika Kladusa                 Visegrad 
##                        1                        1                        1 
##                   Visoko                    Vitez                Vlasenica 
##                        1                        1                        1 
##                  Vogosca               Vukosavlje               Zavidovici 
##                        1                        1                        1 
##                   Zenica                    Zepce                 Zivinice 
##                        1                        1                        1 
##                  Zvornik 
##                        1
#Import montery indexes

library(readxl)

Monetary_Indexes_for_mapping_2_7_2024 <- read_excel("C:/Users/Amra/OneDrive - Direkcija za ekonomsko planiranje/Prijava teme doktorske disertacije/Pisanje disertacije/Monetary Indexes for mapping_2.7.2024.xlsx", 
                                                                   sheet = "QoLponders and sd_maps")
Indexes_QoL <- Monetary_Indexes_for_mapping_2_7_2024

names (Indexes_QoL)
##  [1] "Munic1"                                    
##  [2] "Region"                                    
##  [3] "Entity"                                    
##  [4] "FBiH"                                      
##  [5] "QoLIv1_onlyempl"                           
##  [6] "QoLIv2_allactivy"                          
##  [7] "QoLIv3-Stat_adj wage"                      
##  [8] "WI _onlyempl_HPI"                          
##  [9] "WI _allempl_HPI"                           
## [10] "Stand.wi.ponder_onlyempl"                  
## [11] "Stand.wi.ponder_all activ"                 
## [12] "Stand.HPI"                                 
## [13] "Stand.TI"                                  
## [14] "emplrate2014"                              
## [15] "Average.totalpop2013_14"                   
## [16] "Average.totalpop2023_24"                   
## [17] "Munic"                                     
## [18] "Povrsina_km2"                              
## [19] "pop.per.km2_2013_2014"                     
## [20] "pop.per.km2_2023_2024"                     
## [21] "Rate.change.pop.per.km2"                   
## [22] "Prim.enr.change.per.Pop2013"               
## [23] "Rate.change(prim.enr.per.capita.2023_2013)"
## [24] "rate.change.prim.enrolment"                
## [25] "share_65"                                  
## [26] "Share univ.degre"                          
## [27] "Share no primary education"                
## [28] "Urban.Share"                               
## [29] "Diversity Index-ethnicity"                 
## [30] "DI_ethnic_region"                          
## [31] "Ratio_Munic.region"                        
## [32] "DI_ethnicity_country"                      
## [33] "Diversity Index-religion"                  
## [34] "Diversity Index-mother language"           
## [35] "War_intesity"                              
## [36] "Gender.gap.per.working age_2013"           
## [37] "Gender.em.rate.gap(f-m)"                   
## [38] "majority m=r(0=not)"                       
## [39] "majority m=r(0=not,2=nomajority)"          
## [40] "Nearest_munic_other_entity"                
## [41] "route_m"                                   
## [42] "Route_drive_minutes"                       
## [43] "rtrn_abrd"                                 
## [44] "share_rtrn_abroad"                         
## [45] "Scaled_Stand.wi.ponder_onlyempl"           
## [46] "Scaled_Stand.wi.ponder_all activ"          
## [47] "Scaled_Stand.HPI"                          
## [48] "Scaled_Stand.TI"                           
## [49] "Scaled_Stand.Adj.wage_ponder2"
str(Indexes_QoL)
## tibble [142 × 49] (S3: tbl_df/tbl/data.frame)
##  $ Munic1                                    : chr [1:142] "Banovici" "Banja Luka" "Berkovici" "Bihac" ...
##  $ Region                                    : chr [1:142] "TK" "RS" "RS" "USK" ...
##  $ Entity                                    : chr [1:142] "FBiH" "RS" "RS" "FBiH" ...
##  $ FBiH                                      : num [1:142] 1 0 0 1 0 0 1 1 1 0 ...
##  $ QoLIv1_onlyempl                           : num [1:142] 0.681 0.99 -0.301 -0.538 -0.118 ...
##  $ QoLIv2_allactivy                          : num [1:142] 0.507 1.023 -0.185 -0.559 -0.168 ...
##  $ QoLIv3-Stat_adj wage                      : num [1:142] 0.486 1.29 -0.109 0.134 0.199 ...
##  $ WI _onlyempl_HPI                          : num [1:142] 0.824 1 -0.348 -0.39 -0.225 ...
##  $ WI _allempl_HPI                           : num [1:142] 0.65 1.033 -0.232 -0.411 -0.275 ...
##  $ Stand.wi.ponder_onlyempl                  : num [1:142] 0.752 1.5612 -0.4845 -0.0475 -0.163 ...
##  $ Stand.wi.ponder_all activ                 : num [1:142] 0.5689 1.5955 -0.3624 -0.0692 -0.2158 ...
##  $ Stand.HPI                                 : num [1:142] -0.549 2.415 -0.562 1.727 0.351 ...
##  $ Stand.TI                                  : num [1:142] 0.9549 0.0665 -0.3098 0.9825 -0.7166 ...
##  $ emplrate2014                              : num [1:142] 0.302 0.49 0.199 0.293 0.279 ...
##  $ Average.totalpop2013_14                   : num [1:142] 22813 180509 2040 56300 103955 ...
##  $ Average.totalpop2023_24                   : num [1:142] 22049 185431 1738 54766 103050 ...
##  $ Munic                                     : chr [1:142] "Banovici" "Banja Luka" "Berkovici" "Bihac" ...
##  $ Povrsina_km2                              : num [1:142] 185 1239 264 900 734 ...
##  $ pop.per.km2_2013_2014                     : num [1:142] 123.31 145.7 7.73 62.56 141.61 ...
##  $ pop.per.km2_2023_2024                     : num [1:142] 119.18 149.67 6.58 60.85 140.38 ...
##  $ Rate.change.pop.per.km2                   : num [1:142] 0.03465 -0.02654 0.17348 0.02802 0.00878 ...
##  $ Prim.enr.change.per.Pop2013               : num [1:142] -0.00213 0.00669 -0.04903 -0.03068 -0.00868 ...
##  $ Rate.change(prim.enr.per.capita.2023_2013): num [1:142] 0.01 0.0484 -0.2987 -0.308 -0.0907 ...
##  $ rate.change.prim.enrolment                : num [1:142] -0.0238 0.077 -0.4024 -0.3268 -0.0986 ...
##  $ share_65                                  : num [1:142] 0.1673 0.0927 0.1216 0.1258 0.2365 ...
##  $ Share univ.degre                          : num [1:142] 0.0667 0.1692 0.0573 0.113 0.0912 ...
##  $ Share no primary education                : num [1:142] 0.1326 0.0783 0.1921 0.115 0.1623 ...
##  $ Urban.Share                               : num [1:142] 0.28244 0.750981 0.000001 0.705462 0.392499 ...
##  $ Diversity Index-ethnicity                 : num [1:142] 0.882 0.805 0.85 0.78 0.741 ...
##  $ DI_ethnic_region                          : num [1:142] 0.781 0.685 0.685 0.813 0.685 ...
##  $ Ratio_Munic.region                        : num [1:142] 1.129 1.176 1.241 0.959 1.082 ...
##  $ DI_ethnicity_country                      : num [1:142] 0.37 0.37 0.37 0.37 0.37 ...
##  $ Diversity Index-religion                  : num [1:142] 0.913 0.797 0.85 0.802 0.737 ...
##  $ Diversity Index-mother language           : num [1:142] 0.959 0.845 0.851 0.871 0.758 ...
##  $ War_intesity                              : num [1:142] 0.01234 0.00906 0.01017 0.02259 0.01111 ...
##  $ Gender.gap.per.working age_2013           : num [1:142] -0.1694 -0.0163 -0.0155 -0.0358 -0.0352 ...
##  $ Gender.em.rate.gap(f-m)                   : num [1:142] -33.117 -5.374 -0.243 -8.477 -6.755 ...
##  $ majority m=r(0=not)                       : num [1:142] 1 1 1 1 1 1 1 0 0 1 ...
##  $ majority m=r(0=not,2=nomajority)          : num [1:142] 1 1 1 1 1 1 1 0 0 1 ...
##  $ Nearest_munic_other_entity                : chr [1:142] "Lopare" "Jajce" "Stolac" "Novi Grad" ...
##  $ route_m                                   : num [1:142] 56000 72000 20000 79000 32000 59000 35000 11300 65000 72000 ...
##  $ Route_drive_minutes                       : num [1:142] 74 79 21 86 43 58 39 12 78 81 ...
##  $ rtrn_abrd                                 : num [1:142] 910 11452 50 4232 10972 ...
##  $ share_rtrn_abroad                         : num [1:142] 0.04 0.0619 0.0237 0.0752 0.1019 ...
##  $ Scaled_Stand.wi.ponder_onlyempl           : num [1:142] -0.51 -0.32 -0.801 -0.698 -0.725 ...
##  $ Scaled_Stand.wi.ponder_all activ          : num [1:142] -0.551 -0.309 -0.77 -0.701 -0.735 ...
##  $ Scaled_Stand.HPI                          : num [1:142] -0.463 0.549 -0.468 0.314 -0.156 ...
##  $ Scaled_Stand.TI                           : num [1:142] -0.444 -0.715 -0.83 -0.436 -0.954 ...
##  $ Scaled_Stand.Adj.wage_ponder2             : num [1:142] -0.657 -0.39 -0.823 -0.634 -0.732 ...
summary(Indexes_QoL)
##     Munic1             Region             Entity               FBiH       
##  Length:142         Length:142         Length:142         Min.   :0.0000  
##  Class :character   Class :character   Class :character   1st Qu.:0.0000  
##  Mode  :character   Mode  :character   Mode  :character   Median :1.0000  
##                                                           Mean   :0.5532  
##                                                           3rd Qu.:1.0000  
##                                                           Max.   :1.0000  
##                                                           NA's   :1       
##  QoLIv1_onlyempl    QoLIv2_allactivy   QoLIv3-Stat_adj wage WI _onlyempl_HPI  
##  Min.   :-1.83034   Min.   :-1.87287   Min.   :-1.53894     Min.   :-1.37141  
##  1st Qu.:-0.44319   1st Qu.:-0.48733   1st Qu.:-0.40159     1st Qu.:-0.50450  
##  Median :-0.07984   Median :-0.09638   Median :-0.09818     Median :-0.09722  
##  Mean   : 0.00000   Mean   : 0.00000   Mean   : 0.00000     Mean   : 0.00000  
##  3rd Qu.: 0.33814   3rd Qu.: 0.35832   3rd Qu.: 0.24660     3rd Qu.: 0.25943  
##  Max.   : 6.15275   Max.   : 6.15910   Max.   : 7.69973     Max.   : 6.06975  
##                                                                               
##  WI _allempl_HPI   Stand.wi.ponder_onlyempl Stand.wi.ponder_all activ
##  Min.   :-1.3528   Min.   :-1.3320          Min.   :-1.3417          
##  1st Qu.:-0.4982   1st Qu.:-0.5874          1st Qu.:-0.5810          
##  Median :-0.1278   Median :-0.1651          Median :-0.1665          
##  Mean   : 0.0000   Mean   : 0.0000          Mean   : 0.0000          
##  3rd Qu.: 0.2949   3rd Qu.: 0.3137          3rd Qu.: 0.3309          
##  Max.   : 6.0761   Max.   : 7.1753          Max.   : 7.1820          
##                                                                      
##    Stand.HPI          Stand.TI        emplrate2014     Average.totalpop2013_14
##  Min.   :-2.1201   Min.   :-0.8687   Min.   :-0.6683   Min.   :    69.5       
##  1st Qu.:-0.6519   1st Qu.:-0.6512   1st Qu.: 0.1710   1st Qu.:  6687.1       
##  Median :-0.1488   Median :-0.3098   Median : 0.2305   Median : 16324.0       
##  Mean   : 0.0000   Mean   : 0.0000   Mean   : 0.2377   Mean   : 24545.3       
##  3rd Qu.: 0.4697   3rd Qu.: 0.3271   3rd Qu.: 0.2997   3rd Qu.: 31123.8       
##  Max.   : 3.7341   Max.   : 5.6921   Max.   : 1.0861   Max.   :180508.5       
##                                                                               
##  Average.totalpop2023_24    Munic            Povrsina_km2   
##  Min.   :   105.5        Length:142         Min.   :   9.9  
##  1st Qu.:  5728.5        Class :character   1st Qu.: 150.7  
##  Median : 14967.2        Mode  :character   Median : 295.9  
##  Mean   : 23606.7                           Mean   : 359.7  
##  3rd Qu.: 29688.2                           3rd Qu.: 499.8  
##  Max.   :185430.5                           Max.   :1238.9  
##                                                             
##  pop.per.km2_2013_2014 pop.per.km2_2023_2024 Rate.change.pop.per.km2
##  Min.   :   0.924      Min.   :   1.403      Min.   :-0.43239       
##  1st Qu.:  22.480      1st Qu.:  19.855      1st Qu.: 0.02735       
##  Median :  56.010      Median :  50.716      Median : 0.06566       
##  Mean   : 161.557      Mean   : 157.393      Mean   : 0.06494       
##  3rd Qu.: 117.208      3rd Qu.: 107.195      3rd Qu.: 0.09986       
##  Max.   :6542.828      Max.   :6331.515      Max.   : 0.38818       
##                                                                     
##  Prim.enr.change.per.Pop2013 Rate.change(prim.enr.per.capita.2023_2013)
##  Min.   :-0.053695           Min.   :-0.49690                          
##  1st Qu.:-0.023823           1st Qu.:-0.25547                          
##  Median :-0.017315           Median :-0.15726                          
##  Mean   :-0.016511           Mean   :-0.16319                          
##  3rd Qu.:-0.008582           3rd Qu.:-0.07007                          
##  Max.   : 0.027677           Max.   : 0.25851                          
##                                                                        
##  rate.change.prim.enrolment    share_65       Share univ.degre 
##  Min.   :-0.5591            Min.   :0.07416   Min.   :0.01060  
##  1st Qu.:-0.3127            1st Qu.:0.12702   1st Qu.:0.05223  
##  Median :-0.1981            Median :0.16126   Median :0.06452  
##  Mean   :-0.2109            Mean   :0.21152   Mean   :0.07696  
##  3rd Qu.:-0.1148            3rd Qu.:0.19843   3rd Qu.:0.08904  
##  Max.   : 0.3127            Max.   :6.37641   Max.   :0.32029  
##                                                                
##  Share no primary education  Urban.Share       Diversity Index-ethnicity
##  Min.   :0.03777            Min.   :0.000001   Min.   :0.3418           
##  1st Qu.:0.13050            1st Qu.:0.114391   1st Qu.:0.5991           
##  Median :0.16047            Median :0.263319   Median :0.8044           
##  Mean   :0.16541            Mean   :0.297650   Mean   :0.7561           
##  3rd Qu.:0.19236            3rd Qu.:0.435802   3rd Qu.:0.9091           
##  Max.   :0.44853            Max.   :0.993834   Max.   :0.9963           
##                                                                         
##  DI_ethnic_region Ratio_Munic.region DI_ethnicity_country
##  Min.   :0.3418   Min.   :0.5146     Min.   :0.3699      
##  1st Qu.:0.6846   1st Qu.:0.9616     1st Qu.:0.3699      
##  Median :0.6846   Median :1.1334     Median :0.3699      
##  Mean   :0.6760   Mean   :1.1340     Mean   :0.3699      
##  3rd Qu.:0.7025   3rd Qu.:1.3013     3rd Qu.:0.3699      
##  Max.   :0.9755   Max.   :2.1325     Max.   :0.3699      
##                                                          
##  Diversity Index-religion Diversity Index-mother language  War_intesity     
##  Min.   :0.2257           Min.   :0.3459                  Min.   :0.001459  
##  1st Qu.:0.6024           1st Qu.:0.6174                  1st Qu.:0.012094  
##  Median :0.8099           Median :0.8470                  Median :0.018531  
##  Mean   :0.7592           Mean   :0.7826                  Mean   :0.023415  
##  3rd Qu.:0.9145           3rd Qu.:0.9360                  3rd Qu.:0.025094  
##  Max.   :0.9951           Max.   :0.9962                  Max.   :0.197540  
##                                                                             
##  Gender.gap.per.working age_2013 Gender.em.rate.gap(f-m) majority m=r(0=not)
##  Min.   :-0.92683                Min.   :-168.142        Min.   :0.0000     
##  1st Qu.:-0.07076                1st Qu.: -13.423        1st Qu.:1.0000     
##  Median :-0.03887                Median :  -8.030        Median :1.0000     
##  Mean   :-0.06206                Mean   : -10.432        Mean   :0.8732     
##  3rd Qu.:-0.02606                3rd Qu.:  -4.135        3rd Qu.:1.0000     
##  Max.   : 0.02588                Max.   :   4.069        Max.   :1.0000     
##                                                                             
##  majority m=r(0=not,2=nomajority) Nearest_munic_other_entity    route_m      
##  Min.   :0.0000                   Length:142                 Min.   :  4600  
##  1st Qu.:1.0000                   Class :character           1st Qu.: 15000  
##  Median :1.0000                   Mode  :character           Median : 31500  
##  Mean   :0.9437                                              Mean   : 34917  
##  3rd Qu.:1.0000                                              3rd Qu.: 50250  
##  Max.   :2.0000                                              Max.   :140000  
##                                                                              
##  Route_drive_minutes   rtrn_abrd     share_rtrn_abroad 
##  Min.   :  7.00      Min.   :   12   Min.   :0.009905  
##  1st Qu.: 20.00      1st Qu.:  634   1st Qu.:0.053424  
##  Median : 38.00      Median : 1774   Median :0.099612  
##  Mean   : 41.75      Mean   : 3179   Mean   :0.147327  
##  3rd Qu.: 57.75      3rd Qu.: 3770   3rd Qu.:0.185676  
##  Max.   :150.00      Max.   :25470   Max.   :0.683855  
##                                                        
##  Scaled_Stand.wi.ponder_onlyempl Scaled_Stand.wi.ponder_all activ
##  Min.   :-1.0000                 Min.   :-1.0000                 
##  1st Qu.:-0.8250                 1st Qu.:-0.8212                 
##  Median :-0.7257                 Median :-0.7237                 
##  Mean   :-0.6869                 Mean   :-0.6846                 
##  3rd Qu.:-0.6131                 3rd Qu.:-0.6068                 
##  Max.   : 1.0000                 Max.   : 1.0039                 
##                                                                  
##  Scaled_Stand.HPI  Scaled_Stand.TI   Scaled_Stand.Adj.wage_ponder2
##  Min.   :-1.0000   Min.   :-1.0000   Min.   :-1.0000              
##  1st Qu.:-0.4984   1st Qu.:-0.9337   1st Qu.:-0.8726              
##  Median :-0.3265   Median :-0.8296   Median :-0.8022              
##  Mean   :-0.2757   Mean   :-0.7352   Mean   :-0.7662              
##  3rd Qu.:-0.1152   3rd Qu.:-0.6354   3rd Qu.:-0.7097              
##  Max.   : 1.0000   Max.   : 1.0000   Max.   : 1.0000              
## 
Indexes_QoL$hpi_wage1 <- Indexes_QoL$Stand.HPI/Indexes_QoL$Stand.wi.ponder_onlyempl
Indexes_QoL$hpi_wage2 <- Indexes_QoL$Stand.HPI/Indexes_QoL$`Stand.wi.ponder_all activ`



Indexes_QoL %>% group_by(Munic1) %>% dplyr::select(c(Munic1, Stand.HPI, Stand.wi.ponder_onlyempl, hpi_wage1)) %>%  arrange(desc(hpi_wage1)) #ovo sam uradi nakon Ismirovog maila od 3.4.
## # A tibble: 142 × 4
## # Groups:   Munic1 [142]
##    Munic1            Stand.HPI Stand.wi.ponder_onlyempl hpi_wage1
##    <chr>                 <dbl>                    <dbl>     <dbl>
##  1 Kostajnica           -0.695                 -0.00587    118.  
##  2 Vares                -2.12                  -0.172       12.4 
##  3 Livno                -0.744                 -0.0752       9.89
##  4 Visegrad             -1.23                  -0.136        9.09
##  5 Brod                 -1.21                  -0.243        5.00
##  6 Kupres               -0.731                 -0.164        4.47
##  7 Hadzici               1.01                   0.245        4.15
##  8 K.Dubica             -0.969                 -0.240        4.04
##  9 Bosanski Petrovac    -1.68                  -0.436        3.85
## 10 Milici               -1.12                  -0.310        3.61
## # ℹ 132 more rows
Indexes_QoL %>% group_by(Munic1) %>% dplyr::select(c(Munic1, Stand.HPI, Stand.wi.ponder_onlyempl, hpi_wage1)) %>%  arrange(hpi_wage1) #ovo sam uradi nakon Ismirovog maila od 3.4.
## # A tibble: 142 × 4
## # Groups:   Munic1 [142]
##    Munic1     Stand.HPI Stand.wi.ponder_onlyempl hpi_wage1
##    <chr>          <dbl>                    <dbl>     <dbl>
##  1 Fojnica        0.679                 -0.00166   -409.  
##  2 Foca - RS      0.124                 -0.00197    -62.8 
##  3 Sokolac       -1.30                   0.0336     -38.8 
##  4 Bihac          1.73                  -0.0475     -36.4 
##  5 Kakanj         0.440                 -0.0164     -26.7 
##  6 Olovo          0.674                 -0.0838      -8.05
##  7 Glamoc        -0.737                  0.0978      -7.54
##  8 Ostra Luka     0.493                 -0.0743      -6.63
##  9 Vogosca        1.10                  -0.167       -6.60
## 10 Srebrenica    -0.957                  0.165       -5.79
## # ℹ 132 more rows
Indexes_QoL %>% group_by(Munic1) %>% dplyr::select(c(Munic1, Stand.HPI, `Stand.wi.ponder_all activ`,hpi_wage2)) %>%  arrange(hpi_wage2) #bottom 10
## # A tibble: 142 × 4
## # Groups:   Munic1 [142]
##    Munic1     Stand.HPI `Stand.wi.ponder_all activ` hpi_wage2
##    <chr>          <dbl>                       <dbl>     <dbl>
##  1 Kostajnica    -0.695                    0.000551  -1261.  
##  2 Livno         -0.744                    0.0182      -40.8 
##  3 Bihac          1.73                    -0.0692      -25.0 
##  4 Visegrad      -1.23                     0.0657      -18.8 
##  5 Rogatica      -0.806                    0.0567      -14.2 
##  6 Vogosca        1.10                    -0.149        -7.38
##  7 Kakanj         0.440                   -0.0639       -6.88
##  8 Sokolac       -1.30                     0.235        -5.55
##  9 Glamoc        -0.737                    0.140        -5.28
## 10 Srebrenica    -0.957                    0.187        -5.12
## # ℹ 132 more rows
Indexes_QoL %>% group_by(Munic1) %>% dplyr::select(c(Munic1, Stand.HPI, `Stand.wi.ponder_all activ`,hpi_wage2)) %>%  arrange(desc(hpi_wage2)) #top10
## # A tibble: 142 × 4
## # Groups:   Munic1 [142]
##    Munic1            Stand.HPI `Stand.wi.ponder_all activ` hpi_wage2
##    <chr>                 <dbl>                       <dbl>     <dbl>
##  1 Petrovac             -0.238                    -0.00444     53.6 
##  2 Fojnica               0.679                     0.0302      22.5 
##  3 Vares                -2.12                     -0.173       12.3 
##  4 Olovo                 0.674                     0.0653      10.3 
##  5 Gradiska             -0.417                    -0.0648       6.44
##  6 K.Dubica             -0.969                    -0.176        5.51
##  7 Kupres               -0.731                    -0.160        4.56
##  8 Bosanski Petrovac    -1.68                     -0.393        4.27
##  9 Konjic                1.29                      0.373        3.45
## 10 Milici               -1.12                     -0.347        3.21
## # ℹ 132 more rows
#Merge files

map.Indexes_QoL <- merge (Indexes_QoL, amraGIS.nova, by.x="Munic", by.y = "shapeName", all=T) 
dim(map.Indexes_QoL)
## [1] 142  56
#142 muncicip

unique(map.Indexes_QoL$Munic)
##   [1] "Banovici"                 "Banja Luka"              
##   [3] "Berkovici"                "Bihac"                   
##   [5] "Bijeljina"                "Bileca"                  
##   [7] "Bosanska Krupa"           "Bosanski Petrovac"       
##   [9] "Bosansko Grahovo"         "Bratunac"                
##  [11] "Brcko"                    "Breza"                   
##  [13] "Brod"                     "Bugojno"                 
##  [15] "Busovaca"                 "Buzim"                   
##  [17] "Cajnice"                  "Capljina"                
##  [19] "Cazin"                    "Celic"                   
##  [21] "Celinac"                  "Citluk"                  
##  [23] "Derventa"                 "Doboj"                   
##  [25] "Doboj Istok"              "Doboj Jug"               
##  [27] "Dobretici"                "Domaljevac-Samac"        
##  [29] "Donji Vakuf"              "Donji Zabar"             
##  [31] "Drvar"                    "Foca (FBiH)"             
##  [33] "Foca (RS)"                "Fojnica"                 
##  [35] "Gacko"                    "Glamoc"                  
##  [37] "Gorazde"                  "Gornji Vakuf-Uskoplje"   
##  [39] "Gracanica"                "Gradacac"                
##  [41] "Gradiska"                 "Grude"                   
##  [43] "Hadzici"                  "Han Pijesak"             
##  [45] "Ilidza"                   "Ilijas"                  
##  [47] "Istocna Ilidza"           "Istocni Drvar"           
##  [49] "Istocni Mostar"           "Istocni Stari Grad"      
##  [51] "Istocno Novo Sarajevo"    "Jablanica"               
##  [53] "Jajce"                    "Jezero"                  
##  [55] "Kakanj"                   "Kalesija"                
##  [57] "Kalinovik"                "Kiseljak"                
##  [59] "Kladanj"                  "Kljuc"                   
##  [61] "Knezevo"                  "Konjic"                  
##  [63] "Kostajnica"               "Kotor Varos"             
##  [65] "Kozarska Dubica"          "Kresevo"                 
##  [67] "Krupa na Uni"             "Kupres (FBiH)"           
##  [69] "Kupres (RS)"              "Laktasi"                 
##  [71] "Livno"                    "Lopare"                  
##  [73] "Lukavac"                  "Ljubinje"                
##  [75] "Ljubuski"                 "Maglaj"                  
##  [77] "Milici"                   "Modrica"                 
##  [79] "Mostar"                   "Mrkonjic Grad"           
##  [81] "Neum"                     "Nevesinje"               
##  [83] "Novi Grad"                "Novi Travnik"            
##  [85] "Novo Gorazde"             "Odzak"                   
##  [87] "Olovo"                    "Orasje"                  
##  [89] "Osmaci"                   "Ostra Luka"              
##  [91] "Pale (FBiH)"              "Pale (RS)"               
##  [93] "Pelagicevo"               "Petrovac"                
##  [95] "Petrovo"                  "Posusje"                 
##  [97] "Prijedor"                 "Prnjavor"                
##  [99] "Prozor-Rama"              "Ravno"                   
## [101] "Ribnik"                   "Rogatica"                
## [103] "Rudo"                     "Samac"                   
## [105] "Sanski Most"              "Sapna"                   
## [107] "Sarajevo - Centar"        "Sarajevo - Novi Grad"    
## [109] "Sarajevo - Novo Sarajevo" "Sarajevo - Stari Grad"   
## [111] "Sekovici"                 "Sipovo"                  
## [113] "Siroki Brijeg"            "Sokolac"                 
## [115] "Srbac"                    "Srebrenica"              
## [117] "Srebrenik"                "Stolac"                  
## [119] "Teocak"                   "Tesanj"                  
## [121] "Teslic"                   "Tomislavgrad"            
## [123] "Travnik"                  "Trebinje"                
## [125] "Trnovo (FBiH)"            "Trnovo (RS)"             
## [127] "Tuzla"                    "Ugljevik"                
## [129] "Usora"                    "Vares"                   
## [131] "Velika Kladusa"           "Visegrad"                
## [133] "Visoko"                   "Vitez"                   
## [135] "Vlasenica"                "Vogosca"                 
## [137] "Vukosavlje"               "Zavidovici"              
## [139] "Zenica"                   "Zepce"                   
## [141] "Zivinice"                 "Zvornik"
head(map.Indexes_QoL)
##        Munic     Munic1 Region Entity FBiH QoLIv1_onlyempl QoLIv2_allactivy
## 1   Banovici   Banovici     TK   FBiH    1       0.6810219        0.5070688
## 2 Banja Luka Banja Luka     RS     RS    0       0.9901483        1.0227138
## 3  Berkovici  Berkovici     RS     RS    0      -0.3014406       -0.1854586
## 4      Bihac      Bihac    USK   FBiH    1      -0.5378713       -0.5585231
## 5  Bijeljina  Bijeljina     RS     RS    0      -0.1175975       -0.1677032
## 6     Bileca     Bileca     RS     RS    0      -0.2158090       -0.2041717
##   QoLIv3-Stat_adj wage WI _onlyempl_HPI WI _allempl_HPI
## 1            0.4856811        0.8242549       0.6503018
## 2            1.2898245        1.0001255       1.0326910
## 3           -0.1087296       -0.3479101      -0.2319281
## 4            0.1344120       -0.3904959      -0.4111478
## 5            0.1991883       -0.2250897      -0.2751954
## 6           -0.2990825       -0.3028159      -0.2911786
##   Stand.wi.ponder_onlyempl Stand.wi.ponder_all activ  Stand.HPI    Stand.TI
## 1               0.75202133                0.56891276 -0.5491733  0.95488664
## 2               1.56122940                1.59550887  2.4152123  0.06651418
## 3              -0.48447993               -0.36239360 -0.5617290 -0.30979662
## 4              -0.04745998               -0.06919877  1.7270446  0.98250230
## 5              -0.16304739               -0.21579026  0.3509732 -0.71661445
## 6              -0.24203780               -0.22978801  0.3644000 -0.58004624
##   emplrate2014 Average.totalpop2013_14 Average.totalpop2023_24 Povrsina_km2
## 1    0.3019166                 22813.0                 22049.0        185.0
## 2    0.4897254                180508.5                185430.5       1238.9
## 3    0.1993007                  2039.5                  1738.0        264.0
## 4    0.2925893                 56300.0                 54765.5        900.0
## 5    0.2787604                103954.5                103050.0        734.1
## 6    0.2235159                 10577.0                  9712.0        636.8
##   pop.per.km2_2013_2014 pop.per.km2_2023_2024 Rate.change.pop.per.km2
## 1            123.313514            119.183784             0.034650098
## 2            145.700622            149.673501            -0.026543638
## 3              7.725379              6.583333             0.173475259
## 4             62.555556             60.850556             0.028019465
## 5            141.608092            140.375971             0.008777293
## 6             16.609611             15.251256             0.089065074
##   Prim.enr.change.per.Pop2013 Rate.change(prim.enr.per.capita.2023_2013)
## 1                -0.002125981                                 0.01003370
## 2                 0.006689436                                 0.04841641
## 3                -0.049031625                                -0.29874819
## 4                -0.030683837                                -0.30797592
## 5                -0.008681683                                -0.09071145
## 6                -0.012054458                                -0.05625758
##   rate.change.prim.enrolment   share_65 Share univ.degre
## 1                -0.02379200 0.16729994       0.06668757
## 2                 0.07700402 0.09272306       0.16918758
## 3                -0.40241449 0.12161891       0.05733945
## 4                -0.32683757 0.12582402       0.11303522
## 5                -0.09862310 0.23647433       0.09124274
## 6                -0.13343799 0.20643729       0.08931091
##   Share no primary education Urban.Share Diversity Index-ethnicity
## 1                 0.13259120   0.2824397                 0.8815236
## 2                 0.07833322   0.7509809                 0.8051077
## 3                 0.19208716   0.0000010                 0.8495796
## 4                 0.11503902   0.7054620                 0.7797104
## 5                 0.16225047   0.3924987                 0.7409461
## 6                 0.10851872   0.7047284                 0.9704710
##   DI_ethnic_region Ratio_Munic.region DI_ethnicity_country
## 1        0.7808587          1.1289156            0.3698706
## 2        0.6846210          1.1759904            0.3698706
## 3        0.6846210          1.2409489            0.3698706
## 4        0.8126933          0.9594153            0.3698706
## 5        0.6846210          1.0822720            0.3698706
## 6        0.6846210          1.4175304            0.3698706
##   Diversity Index-religion Diversity Index-mother language War_intesity
## 1                0.9125563                       0.9590498  0.012335464
## 2                0.7974721                       0.8445417  0.009055046
## 3                0.8495635                       0.8513013  0.010170762
## 4                0.8023645                       0.8711129  0.022592320
## 5                0.7365319                       0.7583539  0.011114777
## 6                0.9784840                       0.9865463  0.007603132
##   Gender.gap.per.working age_2013 Gender.em.rate.gap(f-m) majority m=r(0=not)
## 1                     -0.16943017             -33.1165018                   1
## 2                     -0.01625329              -5.3737500                   1
## 3                     -0.01547721              -0.2425079                   1
## 4                     -0.03577110              -8.4770704                   1
## 5                     -0.03521284              -6.7547016                   1
## 6                     -0.00427716               1.0138717                   1
##   majority m=r(0=not,2=nomajority) Nearest_munic_other_entity route_m
## 1                                1                     Lopare   56000
## 2                                1                      Jajce   72000
## 3                                1                     Stolac   20000
## 4                                1                  Novi Grad   79000
## 5                                1                     Teocak   32000
## 6                                1                     Stolac   59000
##   Route_drive_minutes rtrn_abrd share_rtrn_abroad
## 1                  74       910        0.03995960
## 2                  79     11452        0.06188865
## 3                  21        50        0.02365184
## 4                  86      4232        0.07522085
## 5                  43     10972        0.10186139
## 6                  58       118        0.01091885
##   Scaled_Stand.wi.ponder_onlyempl Scaled_Stand.wi.ponder_all activ
## 1                      -0.5100734                       -0.5508298
## 2                      -0.3198349                       -0.3094849
## 3                      -0.8007654                       -0.7697727
## 4                      -0.6980253                       -0.7008449
## 5                      -0.7251990                       -0.7353074
## 6                      -0.7437691                       -0.7385982
##   Scaled_Stand.HPI Scaled_Stand.TI Scaled_Stand.Adj.wage_ponder2  hpi_wage1
## 1       -0.4633220      -0.4440848                    -0.6566048  -0.730263
## 2        0.5494186      -0.7148975                    -0.3897219   1.546994
## 3       -0.4676114      -0.8296127                    -0.8227248   1.159447
## 4        0.3143158      -0.4356664                    -0.6337726 -36.389494
## 5       -0.1557996      -0.9536276                    -0.7320362  -2.152584
## 6       -0.1512125      -0.9119959                    -0.8323682  -1.505550
##     hpi_wage2 shapeISO                 shapeID shapeGroup shapeType
## 1  -0.9653032     <NA> 47562260B73001299105468        BIH      ADM2
## 2   1.5137567     <NA> 47562260B25307751810097        BIH      ADM2
## 3   1.5500523     <NA>  47562260B7976823747309        BIH      ADM2
## 4 -24.9577369     <NA> 47562260B48918375665015        BIH      ADM2
## 5  -1.6264553     <NA>  47562260B7913122040730        BIH      ADM2
## 6  -1.5858096     <NA> 47562260B94562227670273        BIH      ADM2
##                         geometry
## 1 MULTIPOLYGON (((18.54929 44...
## 2 MULTIPOLYGON (((16.7992 44....
## 3 MULTIPOLYGON (((17.95274 43...
## 4 MULTIPOLYGON (((16.20963 44...
## 5 MULTIPOLYGON (((18.92213 44...
## 6 MULTIPOLYGON (((18.46525 42...
tail(map.Indexes_QoL)
##          Munic     Munic1 Region Entity FBiH QoLIv1_onlyempl QoLIv2_allactivy
## 137 Vukosavlje Vukosavlje     RS     RS    0     -0.79137486      -0.83263273
## 138 Zavidovici Zavidovici    ZDK   FBiH    1     -0.54346084      -0.51642276
## 139     Zenica     Zenica    ZDK   FBiH    1      0.38177088       0.40847972
## 140      Zepce      Zepce    ZDK   FBiH    1     -0.07608545      -0.07283633
## 141   Zivinice   Zivinice     TK   FBiH    1     -0.78374385      -0.74124899
## 142    Zvornik    Zvornik     RS     RS    0     -0.44370783      -0.44339250
##     QoLIv3-Stat_adj wage WI _onlyempl_HPI WI _allempl_HPI
## 137          -0.63993892       -0.8549628      -0.8962207
## 138          -0.44389332       -0.6613086      -0.6342705
## 139           0.57934701        0.2731529       0.2998617
## 140          -0.26724029       -0.1257509      -0.1225018
## 141          -0.61482809       -0.6162448      -0.5737499
## 142           0.07216474       -0.5003781      -0.5000627
##     Stand.wi.ponder_onlyempl Stand.wi.ponder_all activ  Stand.HPI   Stand.TI
## 137               -1.1562524                -1.1996817 -1.2173848 -0.4239195
## 138               -0.8152546                -0.7867935 -0.5659168 -0.7856515
## 139                0.3982271                 0.4263417  0.5258143 -0.7241200
## 140               -0.3330547                -0.3296346 -0.9532556 -0.3311029
## 141               -0.5549578                -0.5102263  0.4451746  1.1166603
## 142               -0.7272235                -0.7268916 -0.9524214 -0.3778015
##     emplrate2014 Average.totalpop2013_14 Average.totalpop2023_24 Povrsina_km2
## 137   0.08313211                  4360.0                  4159.0         73.7
## 138   0.14045507                 35915.5                 34403.0        556.4
## 139   0.31311735                110578.0                107540.0        558.5
## 140   0.20988673                 30206.5                 29404.0        282.3
## 141   0.19017826                 57773.0                 57636.0        291.0
## 142   0.20805562                 54248.0                 52157.5        374.4
##     pop.per.km2_2013_2014 pop.per.km2_2023_2024 Rate.change.pop.per.km2
## 137              59.15875              56.43148             0.048328925
## 138              64.54978              61.83142             0.043964189
## 139             197.99105             192.55148             0.028249954
## 140             107.00142             104.15870             0.027292205
## 141             198.53265             198.06186             0.002376987
## 142             144.89316             139.30956             0.040080525
##     Prim.enr.change.per.Pop2013 Rate.change(prim.enr.per.capita.2023_2013)
## 137                -0.016972477                                -0.19447652
## 138                -0.019531957                                -0.16057174
## 139                -0.006447937                                -0.04364083
## 140                -0.025375333                                -0.24108526
## 141                -0.011579804                                -0.11766064
## 142                -0.013853045                                -0.14646375
##     rate.change.prim.enrolment   share_65 Share univ.degre
## 137                -0.23161189 0.09471573       0.02674741
## 138                -0.19592236 0.13648111       0.05131548
## 139                -0.06991567 0.16677554       0.08820744
## 140                -0.26124744 0.12549150       0.05524039
## 141                -0.11975298 0.15829048       0.05755771
## 142                -0.17935561 0.19437231       0.06515265
##     Share no primary education Urban.Share Diversity Index-ethnicity
## 137                  0.2692405   0.0000010                 0.3522997
## 138                  0.1631732   0.2271313                 0.8291437
## 139                  0.1213915   0.6375482                 0.7130138
## 140                  0.1460471   0.1806810                 0.4978777
## 141                  0.1746161   0.2797022                 0.8467879
## 142                  0.1639756   0.1953412                 0.5434690
##     DI_ethnic_region Ratio_Munic.region DI_ethnicity_country
## 137        0.6846210          0.5145909            0.3698706
## 138        0.6902386          1.2012422            0.3698706
## 139        0.6902386          1.0329962            0.3698706
## 140        0.6902386          0.7213124            0.3698706
## 141        0.7808587          1.0844316            0.3698706
## 142        0.6846210          0.7938246            0.3698706
##     Diversity Index-religion Diversity Index-mother language War_intesity
## 137                0.3758664                       0.3679370  0.009848283
## 138                0.8572523                       0.9018098  0.015919110
## 139                0.7298300                       0.8321021  0.009806414
## 140                0.4900191                       0.5021360  0.014543238
## 141                0.8786719                       0.9094565  0.006753920
## 142                0.5407449                       0.5461451  0.048416262
##     Gender.gap.per.working age_2013 Gender.em.rate.gap(f-m) majority m=r(0=not)
## 137                     0.004824259                1.577774                   0
## 138                    -0.032428500               -6.404286                   1
## 139                    -0.077966230              -15.252711                   1
## 140                    -0.034660292               -5.638754                   0
## 141                    -0.087441245              -17.374274                   1
## 142                    -0.036479067               -6.466666                   1
##     majority m=r(0=not,2=nomajority) Nearest_munic_other_entity route_m
## 137                                0                      Odzak   16000
## 138                                1                     Teslic   46000
## 139                                1                     Teslic   67000
## 140                                0                     Teslic   36000
## 141                                1                   Sekovici   36000
## 142                                1                      Sapna   20000
##     Route_drive_minutes rtrn_abrd share_rtrn_abroad
## 137                  13      2302        0.49325048
## 138                  46      2696        0.07491386
## 139                  87      4322        0.03905551
## 140                  55      1833        0.06065720
## 141                  62      3318        0.05743963
## 142                  24      8043        0.13665557
##     Scaled_Stand.wi.ponder_onlyempl Scaled_Stand.wi.ponder_all activ
## 137                      -0.9586939                       -0.9666127
## 138                      -0.8785279                       -0.8695459
## 139                      -0.5932477                       -0.5843471
## 140                      -0.7651665                       -0.7620713
## 141                      -0.8173342                       -0.8045271
## 142                      -0.8578325                       -0.8554634
##     Scaled_Stand.HPI Scaled_Stand.TI Scaled_Stand.Adj.wage_ponder2  hpi_wage1
## 137       -0.6916070      -0.8644020                    -0.9662135  1.0528711
## 138       -0.4690421      -0.9746729                    -0.9087555  0.6941595
## 139       -0.0960676      -0.9559156                    -0.6446071  1.3203881
## 140       -0.6013710      -0.8361077                    -0.8734107  2.8621589
## 141       -0.1236170      -0.3947695                    -0.8418893 -0.8021775
## 142       -0.6010860      -0.8503434                    -0.8031789  1.3096681
##      hpi_wage2 shapeISO                 shapeID shapeGroup shapeType
## 137  1.0147565     <NA> 47562260B11760408730406        BIH      ADM2
## 138  0.7192698     <NA> 47562260B38480252250756        BIH      ADM2
## 139  1.2333168     <NA> 47562260B71839486239008        BIH      ADM2
## 140  2.8918552     <NA> 47562260B65722901280803        BIH      ADM2
## 141 -0.8725043     <NA> 47562260B75753554056783        BIH      ADM2
## 142  1.3102661     <NA> 47562260B26020173487367        BIH      ADM2
##                           geometry
## 137 MULTIPOLYGON (((19.11012 44...
## 138 MULTIPOLYGON (((18.08808 44...
## 139 MULTIPOLYGON (((18.07031 44...
## 140 MULTIPOLYGON (((18.07031 44...
## 141 MULTIPOLYGON (((18.57037 44...
## 142 MULTIPOLYGON (((19.17619 44...
##**************
##CORRELATION
##**************
  
#correlation between indeces
cor.test(map.Indexes_QoL$Stand.HPI, map.Indexes_QoL$Stand.wi.ponder_onlyempl) #0.5885 !kod ismira ovo je 0.76
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$Stand.HPI and map.Indexes_QoL$Stand.wi.ponder_onlyempl
## t = 8.6184, df = 140, p-value = 1.298e-14
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.4695763 0.6868725
## sample estimates:
##       cor 
## 0.5887616
cor.test(map.Indexes_QoL$Stand.HPI, map.Indexes_QoL$`Stand.wi.ponder_all activ`) #0.5867
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$Stand.HPI and map.Indexes_QoL$`Stand.wi.ponder_all activ`
## t = 8.5742, df = 140, p-value = 1.67e-14
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.4672180 0.6852735
## sample estimates:
##       cor 
## 0.5867843
#r = 0.20 – 0.39 is considered a weak relationship. r = 0.40 – 0.59 is considered a moderate relationship. r = 0.60 – 0.79 is considered a strong relationship. r = 0.80 – 1 is considered a very strong relationship

#************
#MAP INDECES
#************

##MAP TRANSPORT

map.Indexes_QoL <- mutate(map.Indexes_QoL, cut.Scaled_Stand.TI1 = cut_width(Scaled_Stand.TI, width = 0.2))

t = ggplot() + 
  geom_sf(data = map.Indexes_QoL, aes(geometry=geometry, fill = cut.Scaled_Stand.TI1), 
          color = "lightgray") + 
  scale_fill_viridis_d() + 
  scale_x_continuous(breaks = c(18, 48))
t1 <- t + 
  ggtitle ("Transport index") + 
  theme(plot.title = element_text(color="darkgray", size=12, face="bold")) +
  guides(fill=guide_legend(title=""))

t1 #ovo je scaled standardizovani index. tako sam nasla i vdijela da je to radio i Ismir, dakle ide od-1 pa do 1 i ljepse ispadne na slici.

#to se zove scaliranje. formula je, ako zelim da ide od -1 do 1 slijedeca (2*(vrijednost-minimum)/(maximum-minimum)-1)

# Plot with enhancements
# Load necessary libraries
library(ggplot2)
library(dplyr)
library(viridis)
## Loading required package: viridisLite
## 
## Attaching package: 'viridis'
## 
## The following object is masked from 'package:maps':
## 
##     unemp
library(sf)

# Create the cut for the Scaled Transport Index
map.Indexes_QoL <- mutate(map.Indexes_QoL, 
                          cut.Scaled_Stand.TI1 = cut_width(Scaled_Stand.TI, width = 0.2))

# Identify the municipalities with the highest and lowest levels
highest_muni <- map.Indexes_QoL %>% 
  filter(Scaled_Stand.TI == max(Scaled_Stand.TI, na.rm = TRUE)) %>% 
  dplyr::select(Munic1, Scaled_Stand.TI, geometry)

lowest_muni <- map.Indexes_QoL %>% 
  filter(Scaled_Stand.TI == min(Scaled_Stand.TI, na.rm = TRUE)) %>% 
  dplyr::select(Munic1, Scaled_Stand.TI, geometry)

# Create the base plot
t <- ggplot(data = map.Indexes_QoL) + 
  geom_sf(aes(geometry = geometry, fill = cut.Scaled_Stand.TI1), 
          color = "lightgray", size = 0.1) + 
  scale_fill_viridis_d(option = "A") +  # Use a different option for color
  scale_x_continuous(breaks = c(18, 48)) + 
  labs(title = "Transport Index", 
       fill = "") +
  theme_minimal(base_size = 12) +  # Use a minimal theme
  theme(plot.title = element_text(color = "darkgray", size = 14, face = "bold"),
        axis.title.x = element_blank(),  # Remove x-axis label
        axis.title.y = element_blank(),  # Remove y-axis label
        plot.caption = element_text(color = "darkred", size = 10, face = "italic"),
        legend.position = "right")

# Add lines from the highest and lowest municipalities to the caption
highest_coords <- st_coordinates(st_centroid(highest_muni$geometry))
lowest_coords <- st_coordinates(st_centroid(lowest_muni$geometry))

# Define a longer line length
line_length <- 1.2  # Adjusted length of the line segments

# Adding the lines with municipality names
t <- t + 
  geom_segment(aes(x = highest_coords[1], y = highest_coords[2], 
                   xend = highest_coords[1], yend = highest_coords[2] - line_length), 
               color = "darkorange", linetype = "solid", size = 0.7) +  # Use a distinct color
  annotate("text", x = highest_coords[1], y = highest_coords[2] - line_length - 0.1, 
           label = highest_muni$Munic1, vjust = 0, hjust = 0.5, 
           color = "darkorange", size = 4) +
  geom_segment(aes(x = lowest_coords[1], y = lowest_coords[2], 
                   xend = lowest_coords[1], yend = lowest_coords[2] + line_length), 
               color = "steelblue", linetype = "solid", size = 0.7) +  # Use a distinct color
  annotate("text", x = lowest_coords[1], y = lowest_coords[2] + line_length + 0.1, 
           label = lowest_muni$Munic1, vjust = 0, hjust = 0.5, 
           color = "steelblue", size = 4)
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
# Print the plot
print(t)
## Warning in geom_segment(aes(x = highest_coords[1], y = highest_coords[2], : All aesthetics have length 1, but the data has 142 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
##   a single row.
## Warning in geom_segment(aes(x = lowest_coords[1], y = lowest_coords[2], : All aesthetics have length 1, but the data has 142 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
##   a single row.

# Print the plot
print(t)
## Warning in geom_segment(aes(x = highest_coords[1], y = highest_coords[2], : All aesthetics have length 1, but the data has 142 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
##   a single row.
## All aesthetics have length 1, but the data has 142 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
##   a single row.

# MAP WAGE all.activity
# radim samo all activity jer mi je on do sada naj logicniji
map.Indexes_QoL <- mutate(map.Indexes_QoL, cut.Scaled.Stand.wi.all.activity = cut_width(`Scaled_Stand.wi.ponder_all activ`, width = 0.2))

w = ggplot() + 
  geom_sf(data = map.Indexes_QoL, aes(geometry=geometry, fill = cut.Scaled.Stand.wi.all.activity), 
          color = "lightgray") +
  theme(legend.title=element_blank()) + scale_fill_viridis_d() + 
  scale_x_continuous(breaks = c(18, 48))
w1 <- w + 
  ggtitle ("Wage index- all activity") + 
  theme(plot.title = element_text(color="darkgray", size=12, face="bold")) +
  guides(fill=guide_legend())
w1

#MORE INCANCE GRAPH
# Load necessary libraries
library(ggplot2)
library(dplyr)
library(viridis)
library(sf)

# Create the cut for the Wage Index
map.Indexes_QoL <- mutate(map.Indexes_QoL, 
                          cut.Scaled.Stand.wi.all.activity = cut_width(`Scaled_Stand.wi.ponder_all activ`, width = 0.2))

# Identify the municipalities with the highest and lowest wage index levels
highest_wage_muni <- map.Indexes_QoL %>% 
  filter(`Scaled_Stand.wi.ponder_all activ` == max(`Scaled_Stand.wi.ponder_all activ`, na.rm = TRUE)) %>% 
  dplyr::select(Munic1, `Scaled_Stand.wi.ponder_all activ`, geometry)

lowest_wage_muni <- map.Indexes_QoL %>% 
  filter(`Scaled_Stand.wi.ponder_all activ` == min(`Scaled_Stand.wi.ponder_all activ`, na.rm = TRUE)) %>% 
  dplyr::select(Munic1, `Scaled_Stand.wi.ponder_all activ`, geometry)

# Create the base plot with improved color palette
w <- ggplot(data = map.Indexes_QoL) + 
  geom_sf(aes(geometry = geometry, fill = cut.Scaled.Stand.wi.all.activity), 
          color = "white", size = 0.1) +  # Use white borders for clarity
  scale_fill_viridis_d(option = "B") +  # A subtle color palette
  scale_x_continuous(breaks = NULL) +  # Remove x-axis ticks
  scale_y_continuous(breaks = NULL) +  # Remove y-axis ticks
  labs(title = "Wage Index - All Activity", 
       fill = "") +
  theme_minimal(base_size = 14) +  # Use a minimal theme
  theme(plot.title = element_text(color = "black", size = 16, face = "bold"),
        axis.title.x = element_blank(),  # Remove x-axis label
        axis.title.y = element_blank(),  # Remove y-axis label
        plot.caption = element_text(color = "darkgray", size = 10, face = "italic"),
        legend.position = "right",
        panel.grid.major = element_blank(),  # Remove major grid lines
        panel.grid.minor = element_blank(),  # Remove minor grid lines
        panel.background = element_blank())   # Clear background

# Add lines from the highest and lowest wage index municipalities
highest_coords_wage <- st_coordinates(st_centroid(highest_wage_muni$geometry))
lowest_coords_wage <- st_coordinates(st_centroid(lowest_wage_muni$geometry))

# Define a suitable line length for wage index plot
line_length_wage <- 1.5  # Length of the line segments

# Adding the lines with municipality names for wage index
w1 <- w + 
  geom_segment(aes(x = highest_coords_wage[1], y = highest_coords_wage[2], 
                   xend = highest_coords_wage[1], yend = highest_coords_wage[2] - line_length_wage), 
               color = "darkorange", linetype = "solid", size = 0.7) +  # Use a distinct color
  annotate("text", x = highest_coords_wage[1], y = highest_coords_wage[2] - line_length_wage - 0.1, 
           label = highest_wage_muni$Munic1, vjust = 0, hjust = 0.5, 
           color = "darkorange", size = 4) +
  geom_segment(aes(x = lowest_coords_wage[1], y = lowest_coords_wage[2], 
                   xend = lowest_coords_wage[1], yend = lowest_coords_wage[2] + line_length_wage), 
               color = "steelblue", linetype = "solid", size = 0.7) +  # Use a distinct color
  annotate("text", x = lowest_coords_wage[1], y = lowest_coords_wage[2] + line_length_wage + 0.1, 
           label = lowest_wage_muni$Munic1, vjust = 0, hjust = 0.5, 
           color = "steelblue", size = 4)

# Print the plot
print(w1)
## Warning in geom_segment(aes(x = highest_coords_wage[1], y = highest_coords_wage[2], : All aesthetics have length 1, but the data has 142 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
##   a single row.
## Warning in geom_segment(aes(x = lowest_coords_wage[1], y = lowest_coords_wage[2], : All aesthetics have length 1, but the data has 142 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
##   a single row.

# MAP HOUSING

map.Indexes_QoL <- mutate(map.Indexes_QoL, cut.Scaled_Stand.HPI = cut_width(Scaled_Stand.HPI, width = 0.2))

h = ggplot() +
  geom_sf(data = map.Indexes_QoL, aes(geometry=geometry, fill = cut.Scaled_Stand.HPI), 
                       color = "lightgray") + 
  theme(legend.title=element_blank()) + 
  scale_fill_viridis_d() + 
  scale_x_continuous(breaks = c(18, 48))
h1 <- h + 
  ggtitle ("Housing index") + 
  theme(plot.title = element_text(color="darkgray", size=12, face="bold")) +
  guides(fill=guide_legend())
h1

#enhanced mao on housing index  
# Load necessary libraries
##library(ggplot2)
##library(dplyr)
##library(viridis)
##library(sf)

# Create the cut for the Housing Price Index (HPI)
map.Indexes_QoL <- mutate(map.Indexes_QoL, 
                          cut.Scaled_Stand.HPI = cut_width(Scaled_Stand.HPI, width = 0.2))

# Identify the municipalities with the highest and lowest HPI
highest_HPI_muni <- map.Indexes_QoL %>% 
  filter(Scaled_Stand.HPI == max(Scaled_Stand.HPI, na.rm = TRUE)) %>% 
  dplyr::select(Munic1, Scaled_Stand.HPI, geometry)

lowest_HPI_muni <- map.Indexes_QoL %>% 
  filter(Scaled_Stand.HPI == min(Scaled_Stand.HPI, na.rm = TRUE)) %>% 
  dplyr::select(Munic1, Scaled_Stand.HPI, geometry)

# Create the base plot with improved color palette for the housing index
h <- ggplot(data = map.Indexes_QoL) + 
  geom_sf(aes(geometry = geometry, fill = cut.Scaled_Stand.HPI), 
          color = "white", size = 0.1) +  # Use white borders for clarity
  scale_fill_viridis_d(option = "B") +  # Subtle color palette
  scale_x_continuous(breaks = NULL) +  # Remove x-axis ticks
  scale_y_continuous(breaks = NULL) +  # Remove y-axis ticks
  labs(title = "Housing Index", 
       fill = "") +
  theme_minimal(base_size = 14) +  # Minimal theme
  theme(plot.title = element_text(color = "black", size = 16, face = "bold"),
        axis.title.x = element_blank(),  # Remove x-axis label
        axis.title.y = element_blank(),  # Remove y-axis label
        plot.caption = element_text(color = "darkgray", size = 10, face = "italic"),
        legend.position = "right",
        panel.grid.major = element_blank(),  # Remove major grid lines
        panel.grid.minor = element_blank(),  # Remove minor grid lines
        panel.background = element_blank())   # Clear background

# Add lines from the highest and lowest HPI municipalities
highest_coords_HPI <- st_coordinates(st_centroid(highest_HPI_muni$geometry))
lowest_coords_HPI <- st_coordinates(st_centroid(lowest_HPI_muni$geometry))

# Define a suitable line length for the housing index plot
line_length_HPI <- 1.5  # Length of the line segments

# Adding the lines with municipality names for HPI
h1 <- h + 
  geom_segment(aes(x = highest_coords_HPI[1], y = highest_coords_HPI[2], 
                   xend = highest_coords_HPI[1], yend = highest_coords_HPI[2] - line_length_HPI), 
               color = "darkorange", linetype = "solid", size = 0.7) +  # Use distinct color
  annotate("text", x = highest_coords_HPI[1], y = highest_coords_HPI[2] - line_length_HPI - 0.1, 
           label = highest_HPI_muni$Munic1, vjust = 0, hjust = 0.5, 
           color = "darkorange", size = 4) +
  geom_segment(aes(x = lowest_coords_HPI[1], y = lowest_coords_HPI[2], 
                   xend = lowest_coords_HPI[1], yend = lowest_coords_HPI[2] + line_length_HPI), 
               color = "steelblue", linetype = "solid", size = 0.7) +  # Use distinct color
  annotate("text", x = lowest_coords_HPI[1], y = lowest_coords_HPI[2] + line_length_HPI + 0.1, 
           label = lowest_HPI_muni$Munic1, vjust = 0, hjust = 0.5, 
           color = "steelblue", size = 4)

# Print the plot
print(h1)
## Warning in geom_segment(aes(x = highest_coords_HPI[1], y = highest_coords_HPI[2], : All aesthetics have length 1, but the data has 142 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
##   a single row.
## Warning in geom_segment(aes(x = lowest_coords_HPI[1], y = lowest_coords_HPI[2], : All aesthetics have length 1, but the data has 142 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
##   a single row.

# MAP EMPLOYMENT RATE
map.Indexes_QoL <- mutate(map.Indexes_QoL, cut.emplrate2014 = cut_width(emplrate2014, width = 0.1))

emp.rate = ggplot() + 
  geom_sf(data = map.Indexes_QoL, 
          aes(geometry = geometry, fill = cut.emplrate2014), 
          color = "lightgray") +  # Set border color to light gray
  theme(legend.title = element_blank()) + 
  scale_fill_viridis_d() + 
  scale_x_continuous(breaks = c(18, 48))

emp.rate1 <- emp.rate + labs (title = "Employment rate 2014")+ 
  theme(plot.title = element_text(color="darkgray", size=12, face="bold"))
emp.rate1

library(gridExtra)
## 
## Attaching package: 'gridExtra'
## 
## The following object is masked from 'package:dplyr':
## 
##     combine
grid.arrange(t1, w1, h1, emp.rate1)
## Warning in geom_segment(aes(x = highest_coords_wage[1], y = highest_coords_wage[2], : All aesthetics have length 1, but the data has 142 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
##   a single row.
## Warning in geom_segment(aes(x = lowest_coords_wage[1], y = lowest_coords_wage[2], : All aesthetics have length 1, but the data has 142 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
##   a single row.
## Warning in geom_segment(aes(x = highest_coords_HPI[1], y = highest_coords_HPI[2], : All aesthetics have length 1, but the data has 142 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
##   a single row.
## Warning in geom_segment(aes(x = lowest_coords_HPI[1], y = lowest_coords_HPI[2], : All aesthetics have length 1, but the data has 142 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
##   a single row.

# MAP QOLI ONLY EMPLOYED
map.Indexes_QoL <- mutate(map.Indexes_QoL, cut.QoLIv1_onlyempl = cut_width(QoLIv1_onlyempl, width = 0.3))

QoLIv1 = ggplot() + 
  geom_sf(data = map.Indexes_QoL, aes(geometry=geometry, fill = cut.QoLIv1_onlyempl),color="lightgray") + 
  theme(legend.title=element_blank()) + 
  scale_fill_viridis_d() + 
  scale_x_continuous(breaks = c(18, 48))
QoLIv1 <- QoLIv1 + labs (title = "QoLIv1_onlyempl")+ 
  theme(plot.title = element_text(color="darkgray", size=12, face="bold"))
QoLIv1

## enhanced QoLiv1 

# Create the cut for QoLIv1_onlyempl
map.Indexes_QoL <- mutate(map.Indexes_QoL, 
                          cut.QoLIv1_onlyempl = cut_width(QoLIv1_onlyempl, width = 0.3))

# Identify the municipalities with the highest and lowest QoLIv1_onlyempl
highest_QoLIv1_muni <- map.Indexes_QoL %>% 
  filter(QoLIv1_onlyempl == max(QoLIv1_onlyempl, na.rm = TRUE)) %>% 
  dplyr::select(Munic1, QoLIv1_onlyempl, geometry)

lowest_QoLIv1_muni <- map.Indexes_QoL %>% 
  filter(QoLIv1_onlyempl == min(QoLIv1_onlyempl, na.rm = TRUE)) %>% 
  dplyr::select(Munic1, QoLIv1_onlyempl, geometry)

# Create the base plot for QoLIv1_onlyempl
QoLIv1 <- ggplot(data = map.Indexes_QoL) + 
  geom_sf(aes(geometry = geometry, fill = cut.QoLIv1_onlyempl), 
          color = "white", size = 0.1) +  # White borders for clarity
  scale_fill_viridis_d(option = "B") +  # Subtle color palette
  scale_x_continuous(breaks = NULL) +  # Remove x-axis ticks
  scale_y_continuous(breaks = NULL) +  # Remove y-axis ticks
  labs(title = "QoLIv1 - Only Employment", 
       fill = "") +
  theme_minimal(base_size = 14) +  # Minimalist theme
  theme(plot.title = element_text(color = "black", size = 16, face = "bold"),
        axis.title.x = element_blank(),  # Remove x-axis label
        axis.title.y = element_blank(),  # Remove y-axis label
        plot.caption = element_text(color = "darkgray", size = 10, face = "italic"),
        legend.position = "right",
        panel.grid.major = element_blank(),  # Remove major grid lines
        panel.grid.minor = element_blank(),  # Remove minor grid lines
        panel.background = element_blank())   # Clear background

# Add lines from the highest and lowest QoLIv1_onlyempl municipalities
highest_coords_QoLIv1 <- st_coordinates(st_centroid(highest_QoLIv1_muni$geometry))
lowest_coords_QoLIv1 <- st_coordinates(st_centroid(lowest_QoLIv1_muni$geometry))

# Define a suitable line length for QoLIv1 plot
line_length_QoLIv1 <- 1.5  # Length of the line segments

# Adding the lines with municipality names for QoLIv1_onlyempl
QoLIv1_plot <- QoLIv1 + 
  geom_segment(aes(x = highest_coords_QoLIv1[1], y = highest_coords_QoLIv1[2], 
                   xend = highest_coords_QoLIv1[1], yend = highest_coords_QoLIv1[2] - line_length_QoLIv1), 
               color = "darkorange", linetype = "solid", size = 0.7) +  # Use distinct color
  annotate("text", x = highest_coords_QoLIv1[1], y = highest_coords_QoLIv1[2] - line_length_QoLIv1 - 0.1, 
           label = highest_QoLIv1_muni$Munic1, vjust = 0, hjust = 0.5, 
           color = "darkorange", size = 4) +
  geom_segment(aes(x = lowest_coords_QoLIv1[1], y = lowest_coords_QoLIv1[2], 
                   xend = lowest_coords_QoLIv1[1], yend = lowest_coords_QoLIv1[2] + line_length_QoLIv1), 
               color = "steelblue", linetype = "solid", size = 0.7) +  # Use distinct color
  annotate("text", x = lowest_coords_QoLIv1[1], y = lowest_coords_QoLIv1[2] + line_length_QoLIv1 + 0.1, 
           label = lowest_QoLIv1_muni$Munic1, vjust = 0, hjust = 0.5, 
           color = "steelblue", size = 4)

# Print the plot
print(QoLIv1_plot)
## Warning in geom_segment(aes(x = highest_coords_QoLIv1[1], y = highest_coords_QoLIv1[2], : All aesthetics have length 1, but the data has 142 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
##   a single row.
## Warning in geom_segment(aes(x = lowest_coords_QoLIv1[1], y = lowest_coords_QoLIv1[2], : All aesthetics have length 1, but the data has 142 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
##   a single row.

## MAp QoLIV2

map.Indexes_QoL <- mutate(map.Indexes_QoL, cut.QoLIv2_allactivy = cut_width(QoLIv2_allactivy, width = 0.3))

QoLIv2 = ggplot() + 
  geom_sf(data = map.Indexes_QoL, aes(geometry=geometry, fill = cut.QoLIv2_allactivy),color="lightgray") + 
  theme(legend.title=element_blank()) + 
  scale_fill_viridis_d() + 
  scale_x_continuous(breaks = c(18, 48))
QoLIv2 <- QoLIv2 + labs (title = "QoLIv2_allactivy")+ 
  theme(plot.title = element_text(color="darkgray", size=12, face="bold"))
QoLIv2

##enhanced QoLIv2  

# Load necessary libraries
library(gridExtra)

# Create the cut for QoLIv2_allactivy
map.Indexes_QoL <- mutate(map.Indexes_QoL, 
                          cut.QoLIv2_allactivy = cut_width(QoLIv2_allactivy, width = 0.3))

# Identify the municipalities with the highest and lowest QoLIv2_allactivy
highest_QoLIv2_muni <- map.Indexes_QoL %>% 
  filter(QoLIv2_allactivy == max(QoLIv2_allactivy, na.rm = TRUE)) %>% 
  dplyr::select(Munic1, QoLIv2_allactivy, geometry)

lowest_QoLIv2_muni <- map.Indexes_QoL %>% 
  filter(QoLIv2_allactivy == min(QoLIv2_allactivy, na.rm = TRUE)) %>% 
  dplyr::select(Munic1, QoLIv2_allactivy, geometry)

# Create the base plot for QoLIv2_allactivy
QoLIv2 <- ggplot(data = map.Indexes_QoL) + 
  geom_sf(aes(geometry = geometry, fill = cut.QoLIv2_allactivy), 
          color = "white", size = 0.1) +  # White borders for clarity
  scale_fill_viridis_d(option = "B") +  # Subtle color palette
  scale_x_continuous(breaks = NULL) +  # Remove x-axis ticks
  scale_y_continuous(breaks = NULL) +  # Remove y-axis ticks
  labs(title = "QoLIv2 - All Activity", 
       fill = "") +
  theme_minimal(base_size = 14) +  # Minimalist theme
  theme(plot.title = element_text(color = "black", size = 16, face = "bold"),
        axis.title.x = element_blank(),  # Remove x-axis label
        axis.title.y = element_blank(),  # Remove y-axis label
        plot.caption = element_text(color = "darkgray", size = 10, face = "italic"),
        legend.position = "right",
        panel.grid.major = element_blank(),  # Remove major grid lines
        panel.grid.minor = element_blank(),  # Remove minor grid lines
        panel.background = element_blank())   # Clear background

# Add lines from the highest and lowest QoLIv2_allactivy municipalities
highest_coords_QoLIv2 <- st_coordinates(st_centroid(highest_QoLIv2_muni$geometry))
lowest_coords_QoLIv2 <- st_coordinates(st_centroid(lowest_QoLIv2_muni$geometry))

# Define a suitable line length for QoLIv2 plot
line_length_QoLIv2 <- 1.5  # Length of the line segments

# Adding the lines with municipality names for QoLIv2_allactivy
QoLIv2_plot <- QoLIv2 + 
  geom_segment(aes(x = highest_coords_QoLIv2[1], y = highest_coords_QoLIv2[2], 
                   xend = highest_coords_QoLIv2[1], yend = highest_coords_QoLIv2[2] - line_length_QoLIv2), 
               color = "darkorange", linetype = "solid", size = 0.7) +  # Use distinct color
  annotate("text", x = highest_coords_QoLIv2[1], y = highest_coords_QoLIv2[2] - line_length_QoLIv2 - 0.1, 
           label = highest_QoLIv2_muni$Munic1, vjust = 0, hjust = 0.5, 
           color = "darkorange", size = 4) +
  geom_segment(aes(x = lowest_coords_QoLIv2[1], y = lowest_coords_QoLIv2[2], 
                   xend = lowest_coords_QoLIv2[1], yend = lowest_coords_QoLIv2[2] + line_length_QoLIv2), 
               color = "steelblue", linetype = "solid", size = 0.7) +  # Use distinct color
  annotate("text", x = lowest_coords_QoLIv2[1], y = lowest_coords_QoLIv2[2] + line_length_QoLIv2 + 0.1, 
           label = lowest_QoLIv2_muni$Munic1, vjust = 0, hjust = 0.5, 
           color = "steelblue", size = 4)

# Print the QoLIv2 plot
print(QoLIv2_plot)
## Warning in geom_segment(aes(x = highest_coords_QoLIv2[1], y = highest_coords_QoLIv2[2], : All aesthetics have length 1, but the data has 142 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
##   a single row.
## Warning in geom_segment(aes(x = lowest_coords_QoLIv2[1], y = lowest_coords_QoLIv2[2], : All aesthetics have length 1, but the data has 142 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
##   a single row.

# Combine the previous QoLIv1 plot with the new QoLIv2 plot in a grid layout

# Remove the legend from QoLIv2 plot
QoLIv2_plot_no_legend <- QoLIv2_plot + theme(legend.position = "none")

# Use grid.arrange to place the plots side by side
grid.arrange(QoLIv1_plot, QoLIv2_plot_no_legend, ncol = 2)
## Warning in geom_segment(aes(x = highest_coords_QoLIv1[1], y = highest_coords_QoLIv1[2], : All aesthetics have length 1, but the data has 142 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
##   a single row.
## Warning in geom_segment(aes(x = lowest_coords_QoLIv1[1], y = lowest_coords_QoLIv1[2], : All aesthetics have length 1, but the data has 142 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
##   a single row.
## Warning in geom_segment(aes(x = highest_coords_QoLIv2[1], y = highest_coords_QoLIv2[2], : All aesthetics have length 1, but the data has 142 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
##   a single row.
## Warning in geom_segment(aes(x = lowest_coords_QoLIv2[1], y = lowest_coords_QoLIv2[2], : All aesthetics have length 1, but the data has 142 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
##   a single row.

#graph correlation QoLI AND population change
cor.test (map.Indexes_QoL$QoLIv1_onlyempl, map.Indexes_QoL$Rate.change.pop.per.km2) #no.corr    
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv1_onlyempl and map.Indexes_QoL$Rate.change.pop.per.km2
## t = -0.90358, df = 140, p-value = 0.3678
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.23788784  0.08970808
## sample estimates:
##         cor 
## -0.07614441
cor.test (map.Indexes_QoL$QoLIv2_allactivy, map.Indexes_QoL$Rate.change.pop.per.km2) #no.corr
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv2_allactivy and map.Indexes_QoL$Rate.change.pop.per.km2
## t = -0.87247, df = 140, p-value = 0.3844
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.23541295  0.09230808
## sample estimates:
##         cor 
## -0.07353738
ggplot(map.Indexes_QoL, aes(x = QoLIv1_onlyempl, y = Rate.change.pop.per.km2)) + 
  geom_point(size=1)+
  geom_text(aes(label = ifelse(Rate.change.pop.per.km2>0.2|Rate.change.pop.per.km2 < c(-0.2),paste0(Munic1)," " )),size=3) +
  geom_text(aes(label = ifelse(QoLIv1_onlyempl>5|QoLIv1_onlyempl < c(-5),paste0(Munic1)," ")),size=3) +
  ggtitle("Corr plot Qoliv3",subtitle = "no.cor")

#Centar i Novo Sarajevo odstupajau. Cudno je da imaju visok QoL a nisku korelaciju.
#Problem moze biti sa stvarnim brojem stanovnika. pa je ipak mozda bolje uzimati upise u skole

#drop Centar i Novo Sarajevo
map.Indexes_QoL.drop <- map.Indexes_QoL %>% filter(as.character (Munic1) != "N.Sarajevo" & Munic1!= "C.Sarajevo")

cor.test(map.Indexes_QoL.drop$QoLIv2_allactivy, map.Indexes_QoL.drop$Rate.change.pop.per.km2)#jos uvijek bez signif.
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL.drop$QoLIv2_allactivy and map.Indexes_QoL.drop$Rate.change.pop.per.km2
## t = -0.9457, df = 138, p-value = 0.346
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.24291307  0.08681541
## sample estimates:
##         cor 
## -0.08024361
cor.test(map.Indexes_QoL.drop$QoLIv1_onlyempl, map.Indexes_QoL.drop$Rate.change.pop.per.km2)#bez signif.
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL.drop$QoLIv1_onlyempl and map.Indexes_QoL.drop$Rate.change.pop.per.km2
## t = -0.98543, df = 138, p-value = 0.3261
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.24608225  0.08346917
## sample estimates:
##         cor 
## -0.08359167
##CORELATION QOL INDECES AND PRIMARY SCHOOL ENROLEMENT
cor.test(map.Indexes_QoL$QoLIv1_onlyempl, map.Indexes_QoL$`Rate.change(prim.enr.per.capita.2023_2013)`)#ovo je ok jer dakle sa rastom qol raste upis 
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv1_onlyempl and map.Indexes_QoL$`Rate.change(prim.enr.per.capita.2023_2013)`
## t = 5.2306, df = 140, p-value = 6.031e-07
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.2566923 0.5335165
## sample estimates:
##       cor 
## 0.4043231
# 0.4043231
ggplot(map.Indexes_QoL, aes(x = QoLIv1_onlyempl, y = `Rate.change(prim.enr.per.capita.2023_2013)`)) + 
  geom_point(size=1) + 
  geom_text(aes(label = ifelse(`Rate.change(prim.enr.per.capita.2023_2013)`>0.3 & QoLIv1_onlyempl < -0.1,paste0(Munic1)," " )),size=3) +
  geom_text(aes(label = ifelse(`Rate.change(prim.enr.per.capita.2023_2013)`< -0.3 & QoLIv1_onlyempl > 0.1,paste0(Munic1)," ")),size=3) +
  ggtitle("Corr plot  QoLIv1_onlyempl",subtitle = "cor=0.4043231")

cor.test(map.Indexes_QoL$QoLIv2_allactivy, map.Indexes_QoL$`Rate.change(prim.enr.per.capita.2023_2013)`)#
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv2_allactivy and map.Indexes_QoL$`Rate.change(prim.enr.per.capita.2023_2013)`
## t = 4.8999, df = 140, p-value = 2.613e-06
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.2325387 0.5148858
## sample estimates:
##       cor 
## 0.3826099
#0.3826099
ggplot(map.Indexes_QoL, aes(x = QoLIv2_allactivy, y = `Rate.change(prim.enr.per.capita.2023_2013)`)) + 
  geom_point(size=1) + 
  geom_text(aes(label = ifelse(`Rate.change(prim.enr.per.capita.2023_2013)`>0 & QoLIv2_allactivy < -0.2,paste0(Munic1)," " )),size=3) +
  geom_text(aes(label = ifelse(`Rate.change(prim.enr.per.capita.2023_2013)`< -0.1 &QoLIv2_allactivy > 0.2,paste0(Munic1)," ")),size=3) +
  ggtitle("Corr plot  QoLIv2_allactivy",subtitle = "cor=0.3826099")

###pozitivna je korelacije i umjereno moderate

##KORELACIJE QOLI AND PRIMARY ENROLMENT SHARE OF TOT POP

cor.test(map.Indexes_QoL$QoLIv1_onlyempl, map.Indexes_QoL$rate.change.prim.enrolment)#
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv1_onlyempl and map.Indexes_QoL$rate.change.prim.enrolment
## t = 5.5172, df = 140, p-value = 1.615e-07
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.2771744 0.5491075
## sample estimates:
##       cor 
## 0.4226062
#0.4226062 

cor.test(map.Indexes_QoL$QoLIv2_allactivy, map.Indexes_QoL$rate.change.prim.enrolment)#
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv2_allactivy and map.Indexes_QoL$rate.change.prim.enrolment
## t = 5.1998, df = 140, p-value = 6.932e-07
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.2544618 0.5318072
## sample estimates:
##       cor 
## 0.4023249
# 0.4023249 

#KORALACIJA
cor.test(map.Indexes_QoL$QoLIv1_onlyempl, map.Indexes_QoL$Rate.change.pop.per.km2)#
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv1_onlyempl and map.Indexes_QoL$Rate.change.pop.per.km2
## t = -0.90358, df = 140, p-value = 0.3678
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.23788784  0.08970808
## sample estimates:
##         cor 
## -0.07614441
#no sing

#SHARE UNIVERSITY DEGREE

cor.test(map.Indexes_QoL$QoLIv1_onlyempl, map.Indexes_QoL$`Share univ.degre`)#sad je ovo normalno dakle sa rastom qol raste gustina
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv1_onlyempl and map.Indexes_QoL$`Share univ.degre`
## t = 10.367, df = 140, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.5544657 0.7430658
## sample estimates:
##       cor 
## 0.6590025
#0.659

cor.test(map.Indexes_QoL$QoLIv2_allactivy, map.Indexes_QoL$`Share univ.degre`)#sad je ovo normalno dakle sa rastom qol raste gustina
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv2_allactivy and map.Indexes_QoL$`Share univ.degre`
## t = 10.779, df = 140, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.5721755 0.7544630
## sample estimates:
##       cor 
## 0.6734301
#0.673

#CORRELATION OF SHARE NO PRIMARY
cor.test(map.Indexes_QoL$QoLIv1_onlyempl, map.Indexes_QoL$`Share no primary education`)#sad je ovo normalno dakle sa rastom qol raste gustina
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv1_onlyempl and map.Indexes_QoL$`Share no primary education`
## t = -4.5749, df = 140, p-value = 1.04e-05
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.4959012 -0.2082794
## sample estimates:
##        cor 
## -0.3606336
#-0.361
cor.test(map.Indexes_QoL$QoLIv2_allactivy, map.Indexes_QoL$`Share no primary education`)#sad je ovo normalno dakle sa rastom qol raste gustina
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv2_allactivy and map.Indexes_QoL$`Share no primary education`
## t = -4.728, df = 140, p-value = 5.467e-06
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.5049263 -0.2197681
## sample estimates:
##        cor 
## -0.3710622
#-0.371

#CORRELATION SHARE URBAN 
cor.test(map.Indexes_QoL$QoLIv1_onlyempl, map.Indexes_QoL$Urban.Share)#
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv1_onlyempl and map.Indexes_QoL$Urban.Share
## t = 6.4361, df = 140, p-value = 1.817e-09
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.3398571 0.5956739
## sample estimates:
##       cor 
## 0.4778335
#0.4778335 
cor.test(map.Indexes_QoL$QoLIv2_allactivy, map.Indexes_QoL$Urban.Share)#
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv2_allactivy and map.Indexes_QoL$Urban.Share
## t = 6.4156, df = 140, p-value = 2.017e-09
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.3385089 0.5946901
## sample estimates:
##      cor 
## 0.476657
#0.476657 

#CORRELATION WAR INTENSITY 
cor.test(map.Indexes_QoL$QoLIv1_onlyempl, map.Indexes_QoL$War_intesity)#
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv1_onlyempl and map.Indexes_QoL$War_intesity
## t = -0.10566, df = 140, p-value = 0.916
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1734016  0.1560274
## sample estimates:
##          cor 
## -0.008929368
#NO sin
cor.test(map.Indexes_QoL$QoLIv2_allactivy, map.Indexes_QoL$War_intesity)#
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv2_allactivy and map.Indexes_QoL$War_intesity
## t = -0.0074211, df = 140, p-value = 0.9941
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1653374  0.1641170
## sample estimates:
##           cor 
## -0.0006271957
#no. sing

#CORRELATION WAR INTENSITY 
cor.test(map.Indexes_QoL$QoLIv1_onlyempl, map.Indexes_QoL$War_intesity)#
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv1_onlyempl and map.Indexes_QoL$War_intesity
## t = -0.10566, df = 140, p-value = 0.916
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1734016  0.1560274
## sample estimates:
##          cor 
## -0.008929368
#NO sin
cor.test(map.Indexes_QoL$QoLIv2_allactivy, map.Indexes_QoL$War_intesity)#
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv2_allactivy and map.Indexes_QoL$War_intesity
## t = -0.0074211, df = 140, p-value = 0.9941
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1653374  0.1641170
## sample estimates:
##           cor 
## -0.0006271957
#no. sing

#CORRELATION WAR INTENSITY 
cor.test(map.Indexes_QoL$QoLIv1_onlyempl, map.Indexes_QoL$share_rtrn_abroad)#
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv1_onlyempl and map.Indexes_QoL$share_rtrn_abroad
## t = -2.5383, df = 140, p-value = 0.01223
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.3619713 -0.0466348
## sample estimates:
##        cor 
## -0.2097508
#-0.2097508 
cor.test(map.Indexes_QoL$QoLIv2_allactivy, map.Indexes_QoL$share_rtrn_abroad)#
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv2_allactivy and map.Indexes_QoL$share_rtrn_abroad
## t = -2.4541, df = 140, p-value = 0.01535
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.3559110 -0.0396912
## sample estimates:
##        cor 
## -0.2030906
#-0.2030906

#CORRELATION OF DIVERSITY
##Ethnicity
cor.test(map.Indexes_QoL$QoLIv1_onlyempl, map.Indexes_QoL$`Diversity Index-ethnicity`) #Nema korelacije
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv1_onlyempl and map.Indexes_QoL$`Diversity Index-ethnicity`
## t = 0.14227, df = 140, p-value = 0.8871
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1530069  0.1764013
## sample estimates:
##        cor 
## 0.01202341
#no.sing
cor.test(map.Indexes_QoL$QoLIv2_allactivy, map.Indexes_QoL$`Diversity Index-ethnicity`)#Nema korelacije
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv2_allactivy and map.Indexes_QoL$`Diversity Index-ethnicity`
## t = 0.3665, df = 140, p-value = 0.7145
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1344525  0.1946948
## sample estimates:
##        cor 
## 0.03096047
#no.sing

#CORRELATION OF DIVERSITY
##Ethnicity RATIO
cor.test(map.Indexes_QoL$QoLIv1_onlyempl, map.Indexes_QoL$Ratio_Munic.region) #Nema korelacije
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv1_onlyempl and map.Indexes_QoL$Ratio_Munic.region
## t = -0.47483, df = 140, p-value = 0.6356
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.2034812  0.1254580
## sample estimates:
##         cor 
## -0.04009795
#no.sing
cor.test(map.Indexes_QoL$QoLIv2_allactivy, map.Indexes_QoL$Ratio_Munic.region)#Nema korelacije
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv2_allactivy and map.Indexes_QoL$Ratio_Munic.region
## t = -0.24818, df = 140, p-value = 0.8044
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1850587  0.1442549
## sample estimates:
##         cor 
## -0.02097071
#no.sing

#Ethnicity yes and no municipality-region version 1

cor.test(map.Indexes_QoL$QoLIv1_onlyempl, map.Indexes_QoL$`majority m=r(0=not)`) #Nema korelacije
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv1_onlyempl and map.Indexes_QoL$`majority m=r(0=not)`
## t = 0.14524, df = 140, p-value = 0.8847
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1527618  0.1766444
## sample estimates:
##        cor 
## 0.01227432
#no.sing
cor.test(map.Indexes_QoL$QoLIv2_allactivy, map.Indexes_QoL$`majority m=r(0=not)`)#Nema korelacije
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv2_allactivy and map.Indexes_QoL$`majority m=r(0=not)`
## t = 0.15977, df = 140, p-value = 0.8733
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1515627  0.1778334
## sample estimates:
##        cor 
## 0.01350161
#no.sing

#Ethnicity yes and no municipality-region version 2
cor.test(map.Indexes_QoL$QoLIv1_onlyempl, map.Indexes_QoL$`majority m=r(0=not,2=nomajority)`) #Nema korelacije
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv1_onlyempl and map.Indexes_QoL$`majority m=r(0=not,2=nomajority)`
## t = 0.30755, df = 140, p-value = 0.7589
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1393397  0.1898984
## sample estimates:
##        cor 
## 0.02598394
#no.sing
cor.test(map.Indexes_QoL$QoLIv2_allactivy, map.Indexes_QoL$`majority m=r(0=not,2=nomajority)`)#Nema korelacije
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv2_allactivy and map.Indexes_QoL$`majority m=r(0=not,2=nomajority)`
## t = 0.34119, df = 140, p-value = 0.7335
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1365517  0.1926366
## sample estimates:
##        cor 
## 0.02882397
#no.sing

##Language
cor.test(map.Indexes_QoL$QoLIv1_onlyempl, map.Indexes_QoL$`Diversity Index-mother language`) #Nema korelacije
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv1_onlyempl and map.Indexes_QoL$`Diversity Index-mother language`
## t = 0.92041, df = 140, p-value = 0.3589
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.0883008  0.2392256
## sample estimates:
##        cor 
## 0.07755455
#no.sing
cor.test(map.Indexes_QoL$QoLIv2_allactivy, map.Indexes_QoL$`Diversity Index-mother language`)#Nema korelacije
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv2_allactivy and map.Indexes_QoL$`Diversity Index-mother language`
## t = 1.0817, df = 140, p-value = 0.2812
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.07480522  0.25199198
## sample estimates:
##        cor 
## 0.09104394
#no.sing

#share of 65+
cor.test(map.Indexes_QoL$QoLIv1_onlyempl, as.numeric(map.Indexes_QoL$share_65)) #no corelation
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv1_onlyempl and as.numeric(map.Indexes_QoL$share_65)
## t = -0.047444, df = 140, p-value = 0.9622
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1686256  0.1608238
## sample estimates:
##          cor 
## -0.004009699
#no sing

cor.test(map.Indexes_QoL$QoLIv2_allactivy, as.numeric (map.Indexes_QoL$share_65))#no corelation
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv2_allactivy and as.numeric(map.Indexes_QoL$share_65)
## t = -0.070957, df = 140, p-value = 0.9435
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1705557  0.1588873
## sample estimates:
##          cor 
## -0.005996895
#no sing

#GENDER GAP ACROSS MUNICIPALITIES
cor.test(map.Indexes_QoL$QoLIv1_onlyempl, as.numeric(map.Indexes_QoL$`Gender.em.rate.gap(f-m)`)) #negative cor
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv1_onlyempl and as.numeric(map.Indexes_QoL$`Gender.em.rate.gap(f-m)`)
## t = -2.5923, df = 140, p-value = 0.01055
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.36584128 -0.05108482
## sample estimates:
##        cor 
## -0.2140112
#-0.2140112 

cor.test(map.Indexes_QoL$QoLIv2_allactivy, as.numeric (map.Indexes_QoL$`Gender.em.rate.gap(f-m)`))#no corelation
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv2_allactivy and as.numeric(map.Indexes_QoL$`Gender.em.rate.gap(f-m)`)
## t = -2.5172, df = 140, p-value = 0.01296
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.36045587 -0.04489559
## sample estimates:
##       cor 
## -0.208084
#-0.208084 


##CORELATION DISTANCE FROM ANOTHER ENTITY

#DISTANCE QOLI
cor.test(map.Indexes_QoL$QoLIv1_onlyempl, as.numeric (log(map.Indexes_QoL$route_m))) #no corelation
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv1_onlyempl and as.numeric(log(map.Indexes_QoL$route_m))
## t = -0.93631, df = 140, p-value = 0.3507
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.2404882  0.0869714
## sample estimates:
##         cor 
## -0.07888604
cor.test(map.Indexes_QoL$QoLIv2_allactivy, as.numeric (log(map.Indexes_QoL$route_m))) #no corelation
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv2_allactivy and as.numeric(log(map.Indexes_QoL$route_m))
## t = -0.98228, df = 140, p-value = 0.3277
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.24413318  0.08312711
## sample estimates:
##         cor 
## -0.08273305
#QoLI and drive
cor.test(map.Indexes_QoL$QoLIv1_onlyempl, as.numeric (log(map.Indexes_QoL$Route_drive_minutes))) #no corelation
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv1_onlyempl and as.numeric(log(map.Indexes_QoL$Route_drive_minutes))
## t = -0.26259, df = 140, p-value = 0.7933
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1862339  0.1430629
## sample estimates:
##         cor 
## -0.02218725
cor.test(map.Indexes_QoL$QoLIv2_allactivy, as.numeric (log(map.Indexes_QoL$Route_drive_minutes))) #no corelation
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv2_allactivy and as.numeric(log(map.Indexes_QoL$Route_drive_minutes))
## t = -0.27342, df = 140, p-value = 0.7849
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.1871171  0.1421663
## sample estimates:
##         cor 
## -0.02310194
#corr density
cor.test(map.Indexes_QoL$QoLIv1_onlyempl, as.numeric (log(map.Indexes_QoL$pop.per.km2_2013_2014))) #yes positive
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv1_onlyempl and as.numeric(log(map.Indexes_QoL$pop.per.km2_2013_2014))
## t = 2.6057, df = 140, p-value = 0.01016
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.05219233 0.36680273
## sample estimates:
##       cor 
## 0.2150705
#0.2150705
cor.test(map.Indexes_QoL$QoLIv2_allactivy, as.numeric (log(map.Indexes_QoL$pop.per.km2_2013_2014))) #yes positive
## 
##  Pearson's product-moment correlation
## 
## data:  map.Indexes_QoL$QoLIv2_allactivy and as.numeric(log(map.Indexes_QoL$pop.per.km2_2013_2014))
## t = 2.4615, df = 140, p-value = 0.01505
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.04029601 0.35643998
## sample estimates:
##       cor 
## 0.2036713
#0.2036713

##regression with amenities

library(dplyr)

#socio-econimic
QoLiv1_decomp1 <- lm(QoLIv1_onlyempl ~ 
                       as.numeric(`Rate.change(prim.enr.per.capita.2023_2013)`) + #marginalni rast upisa u osnovne skole
                       as.numeric(pop.per.km2_2013_2014) + 
                       as.numeric(`Share univ.degre`) + 
                       as.numeric(Urban.Share)+ 
                       `share_65`+
                       as.numeric(`Gender.em.rate.gap(f-m)`), 
                     data=map.Indexes_QoL)

summary (QoLiv1_decomp1)
## 
## Call:
## lm(formula = QoLIv1_onlyempl ~ as.numeric(`Rate.change(prim.enr.per.capita.2023_2013)`) + 
##     as.numeric(pop.per.km2_2013_2014) + as.numeric(`Share univ.degre`) + 
##     as.numeric(Urban.Share) + share_65 + as.numeric(`Gender.em.rate.gap(f-m)`), 
##     data = map.Indexes_QoL)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.31427 -0.32914 -0.02541  0.34437  2.93523 
## 
## Coefficients:
##                                                            Estimate Std. Error
## (Intercept)                                              -8.640e-01  1.533e-01
## as.numeric(`Rate.change(prim.enr.per.capita.2023_2013)`)  1.099e+00  3.607e-01
## as.numeric(pop.per.km2_2013_2014)                        -6.311e-05  1.073e-04
## as.numeric(`Share univ.degre`)                            1.094e+01  1.715e+00
## as.numeric(Urban.Share)                                   3.068e-01  2.770e-01
## share_65                                                  9.171e-03  1.003e-01
## as.numeric(`Gender.em.rate.gap(f-m)`)                    -1.138e-02  3.516e-03
##                                                          t value Pr(>|t|)    
## (Intercept)                                               -5.638 9.67e-08 ***
## as.numeric(`Rate.change(prim.enr.per.capita.2023_2013)`)   3.046  0.00279 ** 
## as.numeric(pop.per.km2_2013_2014)                         -0.588  0.55727    
## as.numeric(`Share univ.degre`)                             6.375 2.68e-09 ***
## as.numeric(Urban.Share)                                    1.108  0.26992    
## share_65                                                   0.091  0.92729    
## as.numeric(`Gender.em.rate.gap(f-m)`)                     -3.236  0.00153 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.6234 on 135 degrees of freedom
## Multiple R-squared:  0.5124, Adjusted R-squared:  0.4907 
## F-statistic: 23.65 on 6 and 135 DF,  p-value: < 2.2e-16
QoLiv1_decomp1a <- lm(QoLIv1_onlyempl ~ 
                       as.numeric(`Prim.enr.change.per.Pop2013`) + #diff u odnsou na br.stanovnika
                       as.numeric(`Share univ.degre`) + 
                       as.numeric(Urban.Share)+ 
                       as.numeric(`Gender.em.rate.gap(f-m)`), 
                     data=map.Indexes_QoL)

summary (QoLiv1_decomp1a)
## 
## Call:
## lm(formula = QoLIv1_onlyempl ~ as.numeric(Prim.enr.change.per.Pop2013) + 
##     as.numeric(`Share univ.degre`) + as.numeric(Urban.Share) + 
##     as.numeric(`Gender.em.rate.gap(f-m)`), data = map.Indexes_QoL)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.98020 -0.36717 -0.01115  0.31362  3.06432 
## 
## Coefficients:
##                                          Estimate Std. Error t value Pr(>|t|)
## (Intercept)                             -0.902745   0.172826  -5.223 6.39e-07
## as.numeric(Prim.enr.change.per.Pop2013)  7.838352   4.726904   1.658  0.09956
## as.numeric(`Share univ.degre`)          10.356066   1.599279   6.475 1.56e-09
## as.numeric(Urban.Share)                  0.439600   0.275709   1.594  0.11314
## as.numeric(`Gender.em.rate.gap(f-m)`)   -0.010002   0.003606  -2.774  0.00631
##                                            
## (Intercept)                             ***
## as.numeric(Prim.enr.change.per.Pop2013) .  
## as.numeric(`Share univ.degre`)          ***
## as.numeric(Urban.Share)                    
## as.numeric(`Gender.em.rate.gap(f-m)`)   ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.6337 on 137 degrees of freedom
## Multiple R-squared:  0.4886, Adjusted R-squared:  0.4736 
## F-statistic: 32.72 on 4 and 137 DF,  p-value: < 2.2e-16
#diversity
QoLiv1_decomp2 <- lm(QoLIv1_onlyempl ~ 
                       Ratio_Munic.region+
                       factor (FBiH) + 
                       factor (FBiH)*Ratio_Munic.region +
                       share_rtrn_abroad + 
                       War_intesity +
                       `majority m=r(0=not)`+
                       log(route_m)+
                       log(Route_drive_minutes)+
                       Urban.Share, 
                     data=map.Indexes_QoL)
summary(QoLiv1_decomp2)
## 
## Call:
## lm(formula = QoLIv1_onlyempl ~ Ratio_Munic.region + factor(FBiH) + 
##     factor(FBiH) * Ratio_Munic.region + share_rtrn_abroad + War_intesity + 
##     `majority m=r(0=not)` + log(route_m) + log(Route_drive_minutes) + 
##     Urban.Share, data = map.Indexes_QoL)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.4692 -0.4366 -0.0692  0.3260  4.8451 
## 
## Coefficients:
##                                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                       0.924212   1.358622   0.680   0.4975    
## Ratio_Munic.region                0.387236   0.403297   0.960   0.3387    
## factor(FBiH)1                     0.683338   0.603026   1.133   0.2592    
## share_rtrn_abroad                -1.123418   0.561753  -2.000   0.0476 *  
## War_intesity                      0.510158   3.073887   0.166   0.8684    
## `majority m=r(0=not)`            -0.189218   0.215540  -0.878   0.3816    
## log(route_m)                     -0.146181   0.174516  -0.838   0.4038    
## log(Route_drive_minutes)          0.004061   0.212155   0.019   0.9848    
## Urban.Share                       1.566165   0.267602   5.853 3.67e-08 ***
## Ratio_Munic.region:factor(FBiH)1 -0.639717   0.523914  -1.221   0.2243    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.7666 on 131 degrees of freedom
##   (1 observation deleted due to missingness)
## Multiple R-squared:  0.2842, Adjusted R-squared:  0.235 
## F-statistic: 5.778 on 9 and 131 DF,  p-value: 9.531e-07
## decomposition all acitivity

#socio-econimic
QoLiv2_decomp1 <- lm(QoLIv2_allactivy ~ 
                       as.numeric(`Rate.change(prim.enr.per.capita.2023_2013)`) + #marginalni rast upisa u osnovne skole
                       as.numeric(pop.per.km2_2013_2014) + 
                       as.numeric(`Share univ.degre`) + 
                       as.numeric(Urban.Share)+ 
                       `share_65`+
                       as.numeric(`Gender.em.rate.gap(f-m)`), 
                     data=map.Indexes_QoL)

summary (QoLiv2_decomp1)
## 
## Call:
## lm(formula = QoLIv2_allactivy ~ as.numeric(`Rate.change(prim.enr.per.capita.2023_2013)`) + 
##     as.numeric(pop.per.km2_2013_2014) + as.numeric(`Share univ.degre`) + 
##     as.numeric(Urban.Share) + share_65 + as.numeric(`Gender.em.rate.gap(f-m)`), 
##     data = map.Indexes_QoL)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.29657 -0.33773 -0.00948  0.35018  2.86086 
## 
## Coefficients:
##                                                            Estimate Std. Error
## (Intercept)                                              -9.331e-01  1.522e-01
## as.numeric(`Rate.change(prim.enr.per.capita.2023_2013)`)  9.492e-01  3.583e-01
## as.numeric(pop.per.km2_2013_2014)                        -9.464e-05  1.066e-04
## as.numeric(`Share univ.degre`)                            1.175e+01  1.704e+00
## as.numeric(Urban.Share)                                   2.823e-01  2.751e-01
## share_65                                                  6.600e-03  9.964e-02
## as.numeric(`Gender.em.rate.gap(f-m)`)                    -1.087e-02  3.492e-03
##                                                          t value Pr(>|t|)    
## (Intercept)                                               -6.130 9.09e-09 ***
## as.numeric(`Rate.change(prim.enr.per.capita.2023_2013)`)   2.649  0.00904 ** 
## as.numeric(pop.per.km2_2013_2014)                         -0.888  0.37600    
## as.numeric(`Share univ.degre`)                             6.898 1.86e-10 ***
## as.numeric(Urban.Share)                                    1.026  0.30670    
## share_65                                                   0.066  0.94729    
## as.numeric(`Gender.em.rate.gap(f-m)`)                     -3.114  0.00226 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.6192 on 135 degrees of freedom
## Multiple R-squared:  0.5191, Adjusted R-squared:  0.4977 
## F-statistic: 24.29 on 6 and 135 DF,  p-value: < 2.2e-16
QoLiv2_decomp1a <- lm(QoLIv2_allactivy ~ 
                        as.numeric(`Prim.enr.change.per.Pop2013`) + #diff u odnsou na br.stanovnika
                        as.numeric(`Share univ.degre`) + 
                        as.numeric(Urban.Share)+ 
                        as.numeric(`Gender.em.rate.gap(f-m)`), 
                      data=map.Indexes_QoL)

summary (QoLiv2_decomp1a)
## 
## Call:
## lm(formula = QoLIv2_allactivy ~ as.numeric(Prim.enr.change.per.Pop2013) + 
##     as.numeric(`Share univ.degre`) + as.numeric(Urban.Share) + 
##     as.numeric(`Gender.em.rate.gap(f-m)`), data = map.Indexes_QoL)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.98301 -0.37272 -0.00993  0.31673  2.98594 
## 
## Coefficients:
##                                          Estimate Std. Error t value Pr(>|t|)
## (Intercept)                             -0.965779   0.171169  -5.642 9.26e-08
## as.numeric(Prim.enr.change.per.Pop2013)  6.147047   4.681580   1.313  0.19137
## as.numeric(`Share univ.degre`)          11.013655   1.583945   6.953 1.33e-10
## as.numeric(Urban.Share)                  0.397992   0.273065   1.457  0.14727
## as.numeric(`Gender.em.rate.gap(f-m)`)   -0.009704   0.003571  -2.717  0.00743
##                                            
## (Intercept)                             ***
## as.numeric(Prim.enr.change.per.Pop2013)    
## as.numeric(`Share univ.degre`)          ***
## as.numeric(Urban.Share)                    
## as.numeric(`Gender.em.rate.gap(f-m)`)   ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.6277 on 137 degrees of freedom
## Multiple R-squared:  0.4985, Adjusted R-squared:  0.4839 
## F-statistic: 34.05 on 4 and 137 DF,  p-value: < 2.2e-16
#diversity
QoLiv2_decomp2 <- lm(QoLIv2_allactivy ~ 
                       Ratio_Munic.region+
                       factor (FBiH) + 
                       factor (FBiH)*Ratio_Munic.region +
                       share_rtrn_abroad + 
                       War_intesity +
                       `majority m=r(0=not)`+
                       log(route_m)+
                       log(Route_drive_minutes)+
                       Urban.Share, 
                     data=map.Indexes_QoL)
summary(QoLiv2_decomp2)
## 
## Call:
## lm(formula = QoLIv2_allactivy ~ Ratio_Munic.region + factor(FBiH) + 
##     factor(FBiH) * Ratio_Munic.region + share_rtrn_abroad + War_intesity + 
##     `majority m=r(0=not)` + log(route_m) + log(Route_drive_minutes) + 
##     Urban.Share, data = map.Indexes_QoL)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.4495 -0.4521 -0.0695  0.3444  4.8756 
## 
## Coefficients:
##                                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                       0.82854    1.35711   0.611   0.5426    
## Ratio_Munic.region                0.54562    0.40285   1.354   0.1779    
## factor(FBiH)1                     0.83758    0.60235   1.391   0.1667    
## share_rtrn_abroad                -1.02341    0.56113  -1.824   0.0705 .  
## War_intesity                      1.07526    3.07046   0.350   0.7268    
## `majority m=r(0=not)`            -0.18569    0.21530  -0.862   0.3900    
## log(route_m)                     -0.16350    0.17432  -0.938   0.3500    
## log(Route_drive_minutes)          0.02545    0.21192   0.120   0.9046    
## Urban.Share                       1.55100    0.26730   5.802 4.66e-08 ***
## Ratio_Munic.region:factor(FBiH)1 -0.78738    0.52333  -1.505   0.1348    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.7657 on 131 degrees of freedom
##   (1 observation deleted due to missingness)
## Multiple R-squared:  0.2861, Adjusted R-squared:  0.237 
## F-statistic: 5.833 on 9 and 131 DF,  p-value: 8.18e-07
##density charts of numeric variable


plot(density(map.Indexes_QoL$Average.totalpop2013_14))

plot(density(map.Indexes_QoL$`Rate.change(prim.enr.per.capita.2023_2013)`))

plot(density(log(map.Indexes_QoL$Average.totalpop2013_14)))

summary(map.Indexes_QoL)
##     Munic              Munic1             Region             Entity         
##  Length:142         Length:142         Length:142         Length:142        
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##       FBiH        QoLIv1_onlyempl    QoLIv2_allactivy   QoLIv3-Stat_adj wage
##  Min.   :0.0000   Min.   :-1.83034   Min.   :-1.87287   Min.   :-1.53894    
##  1st Qu.:0.0000   1st Qu.:-0.44319   1st Qu.:-0.48733   1st Qu.:-0.40159    
##  Median :1.0000   Median :-0.07984   Median :-0.09638   Median :-0.09818    
##  Mean   :0.5532   Mean   : 0.00000   Mean   : 0.00000   Mean   : 0.00000    
##  3rd Qu.:1.0000   3rd Qu.: 0.33814   3rd Qu.: 0.35832   3rd Qu.: 0.24660    
##  Max.   :1.0000   Max.   : 6.15275   Max.   : 6.15910   Max.   : 7.69973    
##  NA's   :1                                                                  
##  WI _onlyempl_HPI   WI _allempl_HPI   Stand.wi.ponder_onlyempl
##  Min.   :-1.37141   Min.   :-1.3528   Min.   :-1.3320         
##  1st Qu.:-0.50450   1st Qu.:-0.4982   1st Qu.:-0.5874         
##  Median :-0.09722   Median :-0.1278   Median :-0.1651         
##  Mean   : 0.00000   Mean   : 0.0000   Mean   : 0.0000         
##  3rd Qu.: 0.25943   3rd Qu.: 0.2949   3rd Qu.: 0.3137         
##  Max.   : 6.06975   Max.   : 6.0761   Max.   : 7.1753         
##                                                               
##  Stand.wi.ponder_all activ   Stand.HPI          Stand.TI      
##  Min.   :-1.3417           Min.   :-2.1201   Min.   :-0.8687  
##  1st Qu.:-0.5810           1st Qu.:-0.6519   1st Qu.:-0.6512  
##  Median :-0.1665           Median :-0.1488   Median :-0.3098  
##  Mean   : 0.0000           Mean   : 0.0000   Mean   : 0.0000  
##  3rd Qu.: 0.3309           3rd Qu.: 0.4697   3rd Qu.: 0.3271  
##  Max.   : 7.1820           Max.   : 3.7341   Max.   : 5.6921  
##                                                               
##   emplrate2014     Average.totalpop2013_14 Average.totalpop2023_24
##  Min.   :-0.6683   Min.   :    69.5        Min.   :   105.5       
##  1st Qu.: 0.1710   1st Qu.:  6687.1        1st Qu.:  5728.5       
##  Median : 0.2305   Median : 16324.0        Median : 14967.2       
##  Mean   : 0.2377   Mean   : 24545.3        Mean   : 23606.7       
##  3rd Qu.: 0.2997   3rd Qu.: 31123.8        3rd Qu.: 29688.2       
##  Max.   : 1.0861   Max.   :180508.5        Max.   :185430.5       
##                                                                   
##   Povrsina_km2    pop.per.km2_2013_2014 pop.per.km2_2023_2024
##  Min.   :   9.9   Min.   :   0.924      Min.   :   1.403     
##  1st Qu.: 150.7   1st Qu.:  22.480      1st Qu.:  19.855     
##  Median : 295.9   Median :  56.010      Median :  50.716     
##  Mean   : 359.7   Mean   : 161.557      Mean   : 157.393     
##  3rd Qu.: 499.8   3rd Qu.: 117.208      3rd Qu.: 107.195     
##  Max.   :1238.9   Max.   :6542.828      Max.   :6331.515     
##                                                              
##  Rate.change.pop.per.km2 Prim.enr.change.per.Pop2013
##  Min.   :-0.43239        Min.   :-0.053695          
##  1st Qu.: 0.02735        1st Qu.:-0.023823          
##  Median : 0.06566        Median :-0.017315          
##  Mean   : 0.06494        Mean   :-0.016511          
##  3rd Qu.: 0.09986        3rd Qu.:-0.008582          
##  Max.   : 0.38818        Max.   : 0.027677          
##                                                     
##  Rate.change(prim.enr.per.capita.2023_2013) rate.change.prim.enrolment
##  Min.   :-0.49690                           Min.   :-0.5591           
##  1st Qu.:-0.25547                           1st Qu.:-0.3127           
##  Median :-0.15726                           Median :-0.1981           
##  Mean   :-0.16319                           Mean   :-0.2109           
##  3rd Qu.:-0.07007                           3rd Qu.:-0.1148           
##  Max.   : 0.25851                           Max.   : 0.3127           
##                                                                       
##     share_65       Share univ.degre  Share no primary education
##  Min.   :0.07416   Min.   :0.01060   Min.   :0.03777           
##  1st Qu.:0.12702   1st Qu.:0.05223   1st Qu.:0.13050           
##  Median :0.16126   Median :0.06452   Median :0.16047           
##  Mean   :0.21152   Mean   :0.07696   Mean   :0.16541           
##  3rd Qu.:0.19843   3rd Qu.:0.08904   3rd Qu.:0.19236           
##  Max.   :6.37641   Max.   :0.32029   Max.   :0.44853           
##                                                                
##   Urban.Share       Diversity Index-ethnicity DI_ethnic_region
##  Min.   :0.000001   Min.   :0.3418            Min.   :0.3418  
##  1st Qu.:0.114391   1st Qu.:0.5991            1st Qu.:0.6846  
##  Median :0.263319   Median :0.8044            Median :0.6846  
##  Mean   :0.297650   Mean   :0.7561            Mean   :0.6760  
##  3rd Qu.:0.435802   3rd Qu.:0.9091            3rd Qu.:0.7025  
##  Max.   :0.993834   Max.   :0.9963            Max.   :0.9755  
##                                                               
##  Ratio_Munic.region DI_ethnicity_country Diversity Index-religion
##  Min.   :0.5146     Min.   :0.3699       Min.   :0.2257          
##  1st Qu.:0.9616     1st Qu.:0.3699       1st Qu.:0.6024          
##  Median :1.1334     Median :0.3699       Median :0.8099          
##  Mean   :1.1340     Mean   :0.3699       Mean   :0.7592          
##  3rd Qu.:1.3013     3rd Qu.:0.3699       3rd Qu.:0.9145          
##  Max.   :2.1325     Max.   :0.3699       Max.   :0.9951          
##                                                                  
##  Diversity Index-mother language  War_intesity     
##  Min.   :0.3459                  Min.   :0.001459  
##  1st Qu.:0.6174                  1st Qu.:0.012094  
##  Median :0.8470                  Median :0.018531  
##  Mean   :0.7826                  Mean   :0.023415  
##  3rd Qu.:0.9360                  3rd Qu.:0.025094  
##  Max.   :0.9962                  Max.   :0.197540  
##                                                    
##  Gender.gap.per.working age_2013 Gender.em.rate.gap(f-m) majority m=r(0=not)
##  Min.   :-0.92683                Min.   :-168.142        Min.   :0.0000     
##  1st Qu.:-0.07076                1st Qu.: -13.423        1st Qu.:1.0000     
##  Median :-0.03887                Median :  -8.030        Median :1.0000     
##  Mean   :-0.06206                Mean   : -10.432        Mean   :0.8732     
##  3rd Qu.:-0.02606                3rd Qu.:  -4.135        3rd Qu.:1.0000     
##  Max.   : 0.02588                Max.   :   4.069        Max.   :1.0000     
##                                                                             
##  majority m=r(0=not,2=nomajority) Nearest_munic_other_entity    route_m      
##  Min.   :0.0000                   Length:142                 Min.   :  4600  
##  1st Qu.:1.0000                   Class :character           1st Qu.: 15000  
##  Median :1.0000                   Mode  :character           Median : 31500  
##  Mean   :0.9437                                              Mean   : 34917  
##  3rd Qu.:1.0000                                              3rd Qu.: 50250  
##  Max.   :2.0000                                              Max.   :140000  
##                                                                              
##  Route_drive_minutes   rtrn_abrd     share_rtrn_abroad 
##  Min.   :  7.00      Min.   :   12   Min.   :0.009905  
##  1st Qu.: 20.00      1st Qu.:  634   1st Qu.:0.053424  
##  Median : 38.00      Median : 1774   Median :0.099612  
##  Mean   : 41.75      Mean   : 3179   Mean   :0.147327  
##  3rd Qu.: 57.75      3rd Qu.: 3770   3rd Qu.:0.185676  
##  Max.   :150.00      Max.   :25470   Max.   :0.683855  
##                                                        
##  Scaled_Stand.wi.ponder_onlyempl Scaled_Stand.wi.ponder_all activ
##  Min.   :-1.0000                 Min.   :-1.0000                 
##  1st Qu.:-0.8250                 1st Qu.:-0.8212                 
##  Median :-0.7257                 Median :-0.7237                 
##  Mean   :-0.6869                 Mean   :-0.6846                 
##  3rd Qu.:-0.6131                 3rd Qu.:-0.6068                 
##  Max.   : 1.0000                 Max.   : 1.0039                 
##                                                                  
##  Scaled_Stand.HPI  Scaled_Stand.TI   Scaled_Stand.Adj.wage_ponder2
##  Min.   :-1.0000   Min.   :-1.0000   Min.   :-1.0000              
##  1st Qu.:-0.4984   1st Qu.:-0.9337   1st Qu.:-0.8726              
##  Median :-0.3265   Median :-0.8296   Median :-0.8022              
##  Mean   :-0.2757   Mean   :-0.7352   Mean   :-0.7662              
##  3rd Qu.:-0.1152   3rd Qu.:-0.6354   3rd Qu.:-0.7097              
##  Max.   : 1.0000   Max.   : 1.0000   Max.   : 1.0000              
##                                                                   
##    hpi_wage1           hpi_wage2            shapeISO           shapeID         
##  Min.   :-408.9546   Min.   :-1260.9845   Length:142         Length:142        
##  1st Qu.:  -0.7481   1st Qu.:   -0.7933   Class :character   Class :character  
##  Median :   0.4229   Median :    0.3799   Mode  :character   Mode  :character  
##  Mean   :  -2.7334   Mean   :   -8.6714                                        
##  3rd Qu.:   1.4637   3rd Qu.:    1.4483                                        
##  Max.   : 118.4704   Max.   :   53.6216                                        
##                                                                                
##   shapeGroup         shapeType                  geometry  
##  Length:142         Length:142         MULTIPOLYGON :142  
##  Class :character   Class :character   epsg:4326    :  0  
##  Mode  :character   Mode  :character   +proj=long...:  0  
##                                                           
##                                                           
##                                                           
##                                                           
##   cut.Scaled_Stand.TI1 cut.Scaled.Stand.wi.all.activity  cut.Scaled_Stand.HPI
##  [-1.1,-0.9]:52        (-0.9,-0.7]:66                   (-0.5,-0.3]:44       
##  (-0.9,-0.7]:48        (-0.7,-0.5]:40                   (-0.3,-0.1]:29       
##  (-0.7,-0.5]:21        [-1.1,-0.9]:14                   (-0.7,-0.5]:28       
##  (-0.5,-0.3]:11        (-0.5,-0.3]:14                   (-0.1,0.1] :16       
##  (-0.1,0.1] : 5        (-0.3,-0.1]: 6                   (0.1,0.3]  :10       
##  (-0.3,-0.1]: 2        (-0.1,0.1] : 1                   (-0.9,-0.7]: 4       
##  (Other)    : 3        (Other)    : 1                   (Other)    :11       
##      cut.emplrate2014    cut.QoLIv1_onlyempl    cut.QoLIv2_allactivy
##  (0.15,0.25] :51      (-0.15,0.15] :31       (-0.45,-0.15]:28       
##  (0.25,0.35] :44      (-0.45,-0.15]:25       (-0.15,0.15] :27       
##  (0.05,0.15] :25      (0.15,0.45]  :22       (0.15,0.45]  :20       
##  (0.35,0.45] :14      (-0.75,-0.45]:14       (-0.75,-0.45]:18       
##  (0.45,0.55] : 3      (-1.05,-0.75]:11       (0.45,0.75]  :13       
##  (-0.05,0.05]: 2      (0.45,0.75]  :10       (-1.05,-0.75]:10       
##  (Other)     : 3      (Other)      :29       (Other)      :26