Análise Espacial

Carregando banco de dados

agro2016 <- read_excel("C:/Users/Maria/Desktop/agro2016.xlsx")
# View(agro2016)

Carregando os shapes

ShapeMG <- st_read("C:/Users/Maria/Desktop/ESPACIAL/MG_Municipios_20222/MG_Municipios_2022.shp")
## Reading layer `MG_Municipios_2022' from data source 
##   `C:\Users\Maria\Desktop\ESPACIAL\MG_Municipios_20222\MG_Municipios_2022.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 853 features and 4 fields
## Geometry type: POLYGON
## Dimension:     XY
## Bounding box:  xmin: -51.04608 ymin: -22.92276 xmax: -39.85683 ymax: -14.23318
## Geodetic CRS:  SIRGAS 2000
plot(ShapeMG)

EstadoMG <- st_read("C:/Users/Maria/Desktop/ESPACIAL/MG_UF_2022/MG_UF_2022.shp")
## Reading layer `MG_UF_2022' from data source 
##   `C:\Users\Maria\Desktop\ESPACIAL\MG_UF_2022\MG_UF_2022.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 1 feature and 5 fields
## Geometry type: POLYGON
## Dimension:     XY
## Bounding box:  xmin: -51.04608 ymin: -22.92276 xmax: -39.85683 ymax: -14.23318
## Geodetic CRS:  SIRGAS 2000
plot(st_geometry(EstadoMG))

MesoMG <- st_read("C:/Users/Maria/Desktop/ESPACIAL/MG_Mesorregioes_2022/MG_Mesorregioes_2022.shp")
## Reading layer `MG_Mesorregioes_2022' from data source 
##   `C:\Users\Maria\Desktop\ESPACIAL\MG_Mesorregioes_2022\MG_Mesorregioes_2022.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 12 features and 4 fields
## Geometry type: POLYGON
## Dimension:     XY
## Bounding box:  xmin: -51.04608 ymin: -22.92276 xmax: -39.85683 ymax: -14.23318
## Geodetic CRS:  SIRGAS 2000
plot(st_geometry(MesoMG))

# Reconhecendo os nomes dos municipios como caracter

ShapeMG$NM_MUN <- as.character(ShapeMG$NM_MUN)
#ShapeMG$NM_MUN

Conhecendo nosso banco de dados

O banco de dados nomeado com Agro2016, foi disponibilizado pelo INPE (Instituto Nacional de Pesquisas Espaciais) e tem como variaveis a Participação agropecuária no valor adicionado e Concentração de focos de calor do estado de Minas Gerais. O Estado de Minas Gerais tem 853 minicipios. A economia de Minas Gerais é uma das mais diversificadas e dinamicas do Brasil, existe uma alta demanda do setor primario tal que, agronegocio e mineração. É bastante importante resaltar a importancia do segundo setor que abrange a industria e a energia. E o terceiro mais nao menos importante é o turismo, cujo o mesmo é importante para desenvolver nossa analise espacial.

Participação Agropecuária no Valor Adicionado

Refere-se à contribuição econômica do setor agropecuário (atividades agrícolas e pecuárias) no Valor Adicionado Bruto (VAB) de uma região, estado ou país.

Concentração de Focos de calor no Estado de Minas Gerais

A concentração de focos de calor é um indicador usado para medir a densidade dos focos de calor (queimadas ou incêndios) em uma área geográfica específica durante um determinado período. Esse cálculo é feito com base em dados de detecção de satélites, que identificam áreas com altas temperaturas associadas a incêndios. Em nosso estudo podemos ver que tivemos uma média de 0.04535 e uma maxima de 1.09.

Summary

summary(ShapeMG$Agropecuária)
## Length  Class   Mode 
##      0   NULL   NULL
summary(ShapeMG$`Focos de calor 2016`)
## Length  Class   Mode 
##      0   NULL   NULL

Concatenando o shapeMG com o banco de Dados do estado de Minas Gerais

ShapeMG <- merge(ShapeMG, agro2016, by.x = "NM_MUN", 
                 by.y = "Territorialidades")

head(ShapeMG)
## Simple feature collection with 6 features and 6 fields
## Geometry type: POLYGON
## Dimension:     XY
## Bounding box:  xmin: -47.67975 ymin: -20.45593 xmax: -42.04511 ymax: -17.7664
## Geodetic CRS:  SIRGAS 2000
##                NM_MUN  CD_MUN SIGLA_UF AREA_KM2 Agropecuária
## 1 Abadia dos Dourados 3100104       MG  880.461        30.22
## 2              Abaeté 3100203       MG 1817.067        28.23
## 3          Abre Campo 3100302       MG  470.551        24.65
## 4             Acaiaca 3100401       MG  101.886        10.84
## 5             Açucena 3100500       MG  815.422        18.45
## 6            Água Boa 3100609       MG 1320.344        26.92
##   Focos de calor 2016                       geometry
## 1                0.09 POLYGON ((-47.45335 -18.469...
## 2                0.06 POLYGON ((-45.50026 -19.225...
## 3                0.01 POLYGON ((-42.42074 -20.397...
## 4                0.00 POLYGON ((-43.12231 -20.433...
## 5                0.04 POLYGON ((-42.43777 -19.175...
## 6                0.11 POLYGON ((-42.32275 -18.175...
#min(ShapeMG$Agropecuária)
#max(ShapeMG$`Focos de calor 2016`)
str(ShapeMG)
## Classes 'sf' and 'data.frame':   846 obs. of  7 variables:
##  $ NM_MUN             : chr  "Abadia dos Dourados" "Abaeté" "Abre Campo" "Acaiaca" ...
##  $ CD_MUN             : chr  "3100104" "3100203" "3100302" "3100401" ...
##  $ SIGLA_UF           : chr  "MG" "MG" "MG" "MG" ...
##  $ AREA_KM2           : num  880 1817 471 102 815 ...
##  $ Agropecuária       : num  30.2 28.2 24.6 10.8 18.4 ...
##  $ Focos de calor 2016: num  0.09 0.06 0.01 0 0.04 0.11 0.08 0.01 0.05 0.13 ...
##  $ geometry           :sfc_POLYGON of length 846; first list element: List of 1
##   ..$ : num [1:2700, 1:2] -47.5 -47.5 -47.5 -47.5 -47.5 ...
##   ..- attr(*, "class")= chr [1:3] "XY" "POLYGON" "sfg"
##  - attr(*, "sf_column")= chr "geometry"
##  - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA
##   ..- attr(*, "names")= chr [1:6] "NM_MUN" "CD_MUN" "SIGLA_UF" "AREA_KM2" ...
ShapeMG$Agropecuária  = as.numeric(ShapeMG$Agropecuária)
ShapeMG$`Focos de calor 2016` = as.numeric(ShapeMG$`Focos de calor 2016`)

Participação da Agropecuária no Valor Adicionado

summary(ShapeMG$Agropecuária)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   0.000   9.418  16.090  18.574  26.040  79.420

Indicadores da Participação Agropecuária para o Estado de Minas Gerais

tm_shape(ShapeMG) + 
  tm_polygons(n = 4, style = "quantile", border.col = "grey80", lwd = 0.5,
              col = "Agropecuária", palette = "Oranges") +
  tm_legend(outside = FALSE, text.size = 0.8) +
  tm_compass(type = "arrow", position = c("left", "bottom"), size = 1.5)

Moran

O Moran é uma estatística para medir a autocorrelação espacial.

Vizinhança

Criando vizinhanças espaciais com base em polígonos.

ShapeMG.nb1 <- poly2nb(ShapeMG, queen=TRUE)

class(ShapeMG.nb1)
## [1] "nb"
ShapeMG.nb1[[1]]
## [1] 212 261 495
ShapeMG.nb1[[2]]
## [1] 171 464 542 603 621

Aplicação do Moran

moran <- moran.plot(ShapeMG$Agropecuária, xlim=c(0.0,79.42),
                    listw = nb2listw(ShapeMG.nb1, style = "W"))

Outros tipos de vizinhancas podem ser calculados:

ShapeMG.nb1[[50]]
## [1] 100 177 290 630 820 822 824
ShapeMG.nb1[[100]]
## [1]  50 290 820
class(ShapeMG.nb1)
## [1] "nb"
vizinhanca = nb2listw(ShapeMG.nb1, style="W",
                      zero.policy=TRUE)
vizinhanca
## Characteristics of weights list object:
## Neighbour list object:
## Number of regions: 846 
## Number of nonzero links: 4772 
## Percentage nonzero weights: 0.6667449 
## Average number of links: 5.640662 
## 
## Weights style: W 
## Weights constants summary:
##     n     nn  S0       S1       S2
## W 846 715716 846 325.1028 3567.552

Monte Carlo

O método de Monte Carlo é usado para testar a significância dos resultados gerados, verificando se o valor observado de Moran’s I é estatisticamente significativo ou apenas resultado do acaso.

moranMC <- moran.mc(ShapeMG$Agropecuária, vizinhanca, nsim = 999)
moranMC
## 
##  Monte-Carlo simulation of Moran I
## 
## data:  ShapeMG$Agropecuária 
## weights: vizinhanca  
## number of simulations + 1: 1000 
## 
## statistic = 0.34924, observed rank = 1000, p-value = 0.001
## alternative hypothesis: greater

O valor de Moran I (0.34924) mostra que essa autocorrelação é positiva moderada, e o baixo p-valor (0.001) indica que esse padrão não é devido ao acaso, sendo estatisticamente significativo.

Histograma do Monte Carlo

hist(moranMC$res)
abline(v = moranMC$statistic, col = "red")

O histograma mostra que a maioria dos valores simulados de Moran I está concentrada em torno de valores próximos de 0, o que seria esperado em um cenário de não autocorrelação espacial. No entanto, o valor observado de Moran I está bem fora dessa faixa, reforçando a ideia de que há uma autocorrelação espacial significativa e que o padrão espacial dos dados de Agropecuária não é aleatório.

mp <- moran.plot(ShapeMG$Agropecuária, 
                 listw = vizinhanca,
                labels = ShapeMG$NM_MUN , cex = 0.5)

Iremos gerar o Moran Local e em seguida o mapa

# Moran Local

lmoran <- localmoran(ShapeMG$Agropecuária , vizinhanca, alternative = "greater")
head(lmoran)
##             Ii          E.Ii       Var.Ii       Z.Ii Pr(z > E(Ii))
## 1  1.100739520 -9.448655e-04 2.655695e-01  2.1378050   0.016266285
## 2  0.362206598 -6.495536e-04 1.093125e-01  1.0974873   0.136214225
## 3  0.151004474 -2.571995e-04 2.394143e-02  0.9775836   0.164140164
## 4  0.343786986 -4.166537e-04 7.013446e-02  1.2997198   0.096848519
## 5  0.007568406 -1.066555e-07 8.105590e-06  2.6583871   0.003925782
## 6 -0.146972618 -4.852673e-04 4.516083e-02 -0.6893173   0.754688200
# Mapa de Moran Local

ShapeMG$Ii <- lmoran[, 1]  # Adiciona os valores de Ii
ShapeMG$p_value <- lmoran[, 5]  # Adiciona os p-valores

Definir as regioes significativas

ShapeMG$significant <- ifelse(ShapeMG$p_value < 0.05, "Significativo", "Não Significativo")

Criar o mapa LISA com clusters

tm_shape(ShapeMG) + 
  tm_polygons(col = "Ii", palette = "-RdBu", style = "quantile", 
              title = "Índice de Moran Local") +  # Mapeia os valores de Ii
  tm_borders("grey80", lwd = 0.5) +  # Bordas
  tm_layout(frame = FALSE, 
            legend.outside = TRUE,  # Coloca a legenda fora do mapa
            legend.title.size = 1.2, 
            legend.text.size = 0.8) +
  tm_facets(by = "significant")  # Separa as regiões significativas e não significativas
## Warning: One tm layer group has duplicated layer types, which are omitted. To
## draw multiple layers of the same type, use multiple layer groups (i.e. specify
## tm_shape prior to each of them).
## Variable(s) "Ii" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.

Mapear somente regiões significativas

tm_shape(subset(ShapeMG, p_value < 0.05)) + 
  tm_polygons(col = "Ii", palette = "-RdBu", style = "quantile", 
              title = "Índice de Moran Local (Significativo)") + 
  tm_borders("grey80", lwd = 0.5) +
  tm_layout(frame = FALSE, 
            legend.outside = TRUE,  
            legend.title.size = 1.2, 
            legend.text.size = 0.8)
## Warning: One tm layer group has duplicated layer types, which are omitted. To
## draw multiple layers of the same type, use multiple layer groups (i.e. specify
## tm_shape prior to each of them).

vamos agora ver o moran local apenas com os significativos e seu mapa

lmoran <- localmoran(ShapeMG$Agropecuária, vizinhanca, alternative = "two.sided")
head(lmoran)
##             Ii          E.Ii       Var.Ii       Z.Ii Pr(z != E(Ii))
## 1  1.100739520 -9.448655e-04 2.655695e-01  2.1378050    0.032532570
## 2  0.362206598 -6.495536e-04 1.093125e-01  1.0974873    0.272428449
## 3  0.151004474 -2.571995e-04 2.394143e-02  0.9775836    0.328280329
## 4  0.343786986 -4.166537e-04 7.013446e-02  1.2997198    0.193697038
## 5  0.007568406 -1.066555e-07 8.105590e-06  2.6583871    0.007851565
## 6 -0.146972618 -4.852673e-04 4.516083e-02 -0.6893173    0.490623601
# Mapa

mp<- moran.plot(as.vector(scale(ShapeMG$Agropecuária)), listw = vizinhanca, labels = ShapeMG$NM_MUN, cex = 0.5)

MCi2 <- localmoran_perm(ShapeMG$Agropecuária, vizinhanca, nsim = 9999)
MCi.df2 <- as.data.frame(MCi2) 

ShapeMG$p  <- MCi.df2$`Pr(folded) Sim`


pal1 <- c("#DE2D26","#FC9272", "#FEE0D2", "grey90")

tm_shape(ShapeMG) + tm_polygons(style="fixed", breaks = c(0, 0.001, 0.01, 0.05, 0.5),
                                col = "p", palette=pal1, border.col = "grey80", lwd = 0.5) +
  tm_legend(outside = TRUE, text.size = .8) +
  tm_layout(frame = FALSE) 

ShapeMG$Ii <- hotspot(MCi2, Prname="Pr(folded) Sim", 
                      cutoff = 0.05, p.adjust = "none")

# Replace NA with ">0.05". This requires that the Ii factor be re-leveled
ShapeMG$Ii <- factor(ShapeMG$Ii, levels=c("High-High","Low-Low", "Low-High", "High-Low", ">0.05"))
ShapeMG$Ii[is.na(ShapeMG$Ii)] <- ">0.05"

pal2 <- c( "#FF0000", "#0000FF", "#a7adf9", "#f4ada8","#ededed")

tm_shape(ShapeMG) + tm_polygons(style="cat", border.col = "grey80", lwd = 0.5,
                                col = "Ii", palette=pal2) +
  tm_legend(outside = TRUE, text.size = .8) +
  tm_layout(frame = FALSE)

Concentração dos focos de calor

summary(ShapeMG$`Focos de calor 2016`)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## 0.00000 0.01000 0.02000 0.04528 0.04000 1.09000

Indicadores para Concentração de Focos de Calor

#border=NA
tm_shape(ShapeMG) + tm_polygons(n=4, style="quantile", border.col = "grey80", lwd = 0.5,
                                col = "Focos de calor 2016", palette="Reds") +
  tm_legend(outside = FALSE, text.size = 0.8)  +
  tm_layout(frame = FALSE) +
  tm_compass(type = "arrow", position = c("left", "bottom"), size = 1.5)

Moran

Vizinhança

criando vizinhanças espaciais com base em polígonos.

ShapeMG.nb1 <- poly2nb(ShapeMG, queen=TRUE)

class(ShapeMG.nb1)
## [1] "nb"
ShapeMG.nb1[[1]]
## [1] 212 261 495
ShapeMG.nb1[[2]]
## [1] 171 464 542 603 621
summary(ShapeMG$`Focos de calor 2016`)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## 0.00000 0.01000 0.02000 0.04528 0.04000 1.09000
# Moran


moran <- moran.plot(ShapeMG$`Focos de calor 2016`, xlim=c(0.0,1.09),
                    listw = nb2listw(ShapeMG.nb1, style = "W"))

Outros tipos de vizinhanças

ShapeMG.nb1[[50]]
## [1] 100 177 290 630 820 822 824
ShapeMG.nb1[[100]]
## [1]  50 290 820
class(ShapeMG.nb1)
## [1] "nb"
vizinhanca = nb2listw(ShapeMG.nb1, style="W",
                      zero.policy=TRUE)
vizinhanca
## Characteristics of weights list object:
## Neighbour list object:
## Number of regions: 846 
## Number of nonzero links: 4772 
## Percentage nonzero weights: 0.6667449 
## Average number of links: 5.640662 
## 
## Weights style: W 
## Weights constants summary:
##     n     nn  S0       S1       S2
## W 846 715716 846 325.1028 3567.552

Monte Carlo

moranMC <- moran.mc(ShapeMG$`Focos de calor 2016`, vizinhanca, nsim = 999)
moranMC
## 
##  Monte-Carlo simulation of Moran I
## 
## data:  ShapeMG$`Focos de calor 2016` 
## weights: vizinhanca  
## number of simulations + 1: 1000 
## 
## statistic = 0.4278, observed rank = 1000, p-value = 0.001
## alternative hypothesis: greater

O valor de Moran I (0.4278) mostra que essa autocorrelação é positiva moderada, e o baixo p-valor (0.001) indica que esse padrão não é devido ao acaso, sendo estatisticamente significativo.

Iremos agora plotar um histograma para o Moran Monte Carlo

hist(moranMC$res)

abline(v = moranMC$statistic, col = "red")

O histograma mostra que a maioria dos valores simulados de Moran I está concentrada em torno de valores próximos de 0, o que seria esperado em um cenário de não autocorrelação espacial. No entanto, o valor observado de Moran I está bem fora dessa faixa, reforçando a ideia de que há uma autocorrelação espacial significativa e que o padrão espacial dos dados de Agropecuária não é aleatório.

Moran Local e Mapa

# Moran Local

lmoran <- localmoran(ShapeMG$`Focos de calor 2016` , vizinhanca, alternative = "greater")
head(lmoran)
##            Ii          E.Ii       Var.Ii       Z.Ii Pr(z > E(Ii))
## 1  1.18020608 -2.660871e-04 0.0748388354  4.3151137  7.976040e-06
## 2  0.02104305 -2.881973e-05 0.0048530475  0.3024794  3.811433e-01
## 3  0.09590594 -1.656685e-04 0.0154226698  0.7735979  2.195843e-01
## 4  0.07782490 -2.728824e-04 0.0459403326  0.3643692  3.577912e-01
## 5  0.01718244 -3.715063e-06 0.0002823358  1.0228119  1.531984e-01
## 6 -0.08696473 -5.573390e-04 0.0518643543 -0.3794167  6.478108e-01
# Mapa de Moran Local

ShapeMG$Ii <- lmoran[, 1]  # Adiciona os valores de Ii
ShapeMG$p_value <- lmoran[, 5]  # Adiciona os p-valores

Definir as regoes significativas

# Definir as regoes significativas

ShapeMG$significant <- ifelse(ShapeMG$p_value < 0.05, "Significativo", "Não Significativo")
# Criar o mapa LISA com clusters

tm_shape(ShapeMG) + 
  tm_polygons(col = "Ii", palette = "-RdBu", style = "quantile", 
              title = "Índice de Moran Local") +  # Mapeia os valores de Ii
  tm_borders("grey80", lwd = 0.5) +  # Bordas
  tm_layout(frame = FALSE, 
            legend.outside = TRUE,  # Coloca a legenda fora do mapa
            legend.title.size = 1.2, 
            legend.text.size = 0.8) +
  tm_facets(by = "significant")  # Separa as regiões significativas e não significativas
## Warning: One tm layer group has duplicated layer types, which are omitted. To
## draw multiple layers of the same type, use multiple layer groups (i.e. specify
## tm_shape prior to each of them).
## Variable(s) "Ii" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.

# Mapear somente regiões significativas

tm_shape(subset(ShapeMG, p_value < 0.05)) + 
  tm_polygons(col = "Ii", palette = "-RdBu", style = "quantile", 
              title = "Índice de Moran Local (Significativo)") + 
  tm_borders("grey80", lwd = 0.5) +
  tm_layout(frame = FALSE, 
            legend.outside = TRUE,  
            legend.title.size = 1.2, 
            legend.text.size = 0.8)
## Warning: One tm layer group has duplicated layer types, which are omitted. To
## draw multiple layers of the same type, use multiple layer groups (i.e. specify
## tm_shape prior to each of them).

# vamos agora ver o moran local apenas com os significativos 

lmoran <- localmoran(ShapeMG$`Focos de calor 2016`, vizinhanca, alternative = "two.sided")
head(lmoran)
##            Ii          E.Ii       Var.Ii       Z.Ii Pr(z != E(Ii))
## 1  1.18020608 -2.660871e-04 0.0748388354  4.3151137   1.595208e-05
## 2  0.02104305 -2.881973e-05 0.0048530475  0.3024794   7.622866e-01
## 3  0.09590594 -1.656685e-04 0.0154226698  0.7735979   4.391686e-01
## 4  0.07782490 -2.728824e-04 0.0459403326  0.3643692   7.155824e-01
## 5  0.01718244 -3.715063e-06 0.0002823358  1.0228119   3.063968e-01
## 6 -0.08696473 -5.573390e-04 0.0518643543 -0.3794167   7.043785e-01
# Mapa

mp<- moran.plot(as.vector(scale(ShapeMG$`Focos de calor 2016`)), listw = vizinhanca, labels = ShapeMG$NM_MUN, cex = 0.5)

MCi2 <- localmoran_perm(ShapeMG$`Focos de calor 2016`, vizinhanca, nsim = 9999)
MCi.df2 <- as.data.frame(MCi2) 

ShapeMG$p  <- MCi.df2$`Pr(folded) Sim`


pal1 <- c("#DE2D26","#FC9272", "#FEE0D2", "grey90")

tm_shape(ShapeMG) + tm_polygons(style="fixed", breaks = c(0, 0.001, 0.01, 0.05, 0.5),
                                col = "p", palette=pal1, border.col = "grey80", lwd = 0.5) +
  tm_legend(outside = TRUE, text.size = .8) +
  tm_layout(frame = FALSE) 

ShapeMG$Ii <- hotspot(MCi2, Prname="Pr(folded) Sim", 
                      cutoff = 0.05, p.adjust = "none")

# Replace NA with ">0.05". This requires that the Ii factor be re-leveled
ShapeMG$Ii <- factor(ShapeMG$Ii, levels=c("High-High","Low-Low", "Low-High", "High-Low", ">0.05"))
ShapeMG$Ii[is.na(ShapeMG$Ii)] <- ">0.05"

pal2 <- c( "#FF0000", "#0000FF", "#a7adf9", "#f4ada8","#ededed")

tm_shape(ShapeMG) + tm_polygons(style="cat", border.col = "grey80", lwd = 0.5,
                                col = "Ii", palette=pal2) +
  tm_legend(outside = TRUE, text.size = .8) +
  tm_layout(frame = FALSE)