library(spdplyr)
## Loading required package: dplyr
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
## Loading required package: sp
library(purrrlyr)
library(tidyverse)
## Loading tidyverse: ggplot2
## Loading tidyverse: tibble
## Loading tidyverse: tidyr
## Loading tidyverse: readr
## Loading tidyverse: purrr
## Conflicts with tidy packages ----------------------------------------------
## filter(): dplyr, stats
## lag():    dplyr, stats
library(dunn.test)

data_barri <- read.csv("/srv/shiny-server/barriossust/barrios_data.csv",sep=";")
databr <- readRDS("/srv/shiny-server/barriossust/Data/barrios_merged.RDS")
databr$MANZENT <- as.character(as.numeric(databr$MANZENT))
datawk15 <- readRDS("/srv/shiny-server/barriossust/Data/accesibility_score_final_15.RDS")
datawk10 <- readRDS("/srv/shiny-server/barriossust/Data/accesibility_score_final.RDS")

final1 <- databr@data %>% left_join(datawk15, by = c("MANZENT" = "ID_W"))
final1 <- data_barri %>% left_join(final1, by = c("Comp" = "BARRIO"))
## Warning: Column `Comp`/`BARRIO` joining factors with different levels,
## coercing to character vector
final1$Barrio <- NULL

final2 <- databr@data %>% left_join(datawk10, by = c("MANZENT" = "ID_W"))
final2 <- data_barri %>% left_join(final2, by = c("Comp" = "BARRIO"))
## Warning: Column `Comp`/`BARRIO` joining factors with different levels,
## coercing to character vector
final2$Barrio <- NULL

#WK15

shapiro.test(final1$listo)
## 
##  Shapiro-Wilk normality test
## 
## data:  final1$listo
## W = 0.90395, p-value < 2.2e-16
kruskal.test(final1$listo~factor(final1$Localizacion))
## 
##  Kruskal-Wallis rank sum test
## 
## data:  final1$listo by factor(final1$Localizacion)
## Kruskal-Wallis chi-squared = 859.87, df = 2, p-value < 2.2e-16
dunn.test(final1$listo,factor(final1$Localizacion),list=T,table = F,kw=F)
## 
##                            Comparison of x by group                            
##                                 (No adjustment)                                
## 
## List of pairwise comparisons: Z statistic (p-value)
## --------------------------------------------
## central - pericentral   : -4.734154 (0.0000)
## central - periferia     :  19.34802 (0.0000)
## pericentral - periferia :  28.66764 (0.0000)
dunn.test(final1$listo,factor(final1$Ciudad),list=T,table = F,kw=F)
## 
##                            Comparison of x by group                            
##                                 (No adjustment)                                
## 
## List of pairwise comparisons: Z statistic (p-value)
## --------------------------------------------------------
## Copiapo - Gran Concepcion           :  2.395383 (0.0083)
## Copiapo - Gran Coquimbo             : -13.71252 (0.0000)
## Gran Concepcion - Gran Coquimbo     : -19.26950 (0.0000)
## Copiapo - Santiago                  : -11.17613 (0.0000)
## Gran Concepcion - Santiago          : -17.37805 (0.0000)
## Gran Coquimbo - Santiago            :  5.131989 (0.0000)
## Copiapo - Temuco - Padrelas         : -11.72018 (0.0000)
## Gran Concepcion - Temuco - Padrelas : -16.33241 (0.0000)
## Gran Coquimbo - Temuco - Padrelas   :  1.413731 (0.0787)
## Santiago - Temuco - Padrelas        : -2.963080 (0.0015)
## Copiapo - Valdivia                  : -24.91279 (0.0000)
## Gran Concepcion - Valdivia          : -29.24450 (0.0000)
## Gran Coquimbo - Valdivia            : -16.26417 (0.0000)
## Santiago - Valdivia                 : -20.51610 (0.0000)
## Temuco - Padrelas - Valdivia        : -16.59896 (0.0000)
#WK10

shapiro.test(final2$listo)
## 
##  Shapiro-Wilk normality test
## 
## data:  final2$listo
## W = 0.80546, p-value < 2.2e-16
kruskal.test(final2$listo~factor(final2$Localizacion))
## 
##  Kruskal-Wallis rank sum test
## 
## data:  final2$listo by factor(final2$Localizacion)
## Kruskal-Wallis chi-squared = 471.18, df = 2, p-value < 2.2e-16
dunn.test(final2$listo,factor(final2$Localizacion),list=T,table = F,kw=F)
## 
##                            Comparison of x by group                            
##                                 (No adjustment)                                
## 
## List of pairwise comparisons: Z statistic (p-value)
## --------------------------------------------
## central - pericentral   : -4.889847 (0.0000)
## central - periferia     :  13.21145 (0.0000)
## pericentral - periferia :  21.47989 (0.0000)
dunn.test(final2$listo,factor(final2$Ciudad),list=T,table = F,kw=F)
## 
##                            Comparison of x by group                            
##                                 (No adjustment)                                
## 
## List of pairwise comparisons: Z statistic (p-value)
## --------------------------------------------------------
## Copiapo - Gran Concepcion           :  3.412337 (0.0003)
## Copiapo - Gran Coquimbo             : -9.320235 (0.0000)
## Gran Concepcion - Gran Coquimbo     : -15.30349 (0.0000)
## Copiapo - Santiago                  : -9.686530 (0.0000)
## Gran Concepcion - Santiago          : -16.94046 (0.0000)
## Gran Coquimbo - Santiago            :  0.738121 (0.2302)
## Copiapo - Temuco - Padrelas         : -7.870216 (0.0000)
## Gran Concepcion - Temuco - Padrelas : -12.97746 (0.0000)
## Gran Coquimbo - Temuco - Padrelas   :  1.037165 (0.1498)
## Santiago - Temuco - Padrelas        :  0.520912 (0.3012)
## Copiapo - Valdivia                  : -21.89543 (0.0000)
## Gran Concepcion - Valdivia          : -26.76123 (0.0000)
## Gran Coquimbo - Valdivia            : -16.63018 (0.0000)
## Santiago - Valdivia                 : -18.14095 (0.0000)
## Temuco - Padrelas - Valdivia        : -16.63836 (0.0000)