library(ape)
set.seed(12345)
MO=rnorm(n=150, mean= 3, sd=0.5)
xy= expand.grid(x=seq(1,10), y =seq(1,15))
df=data.frame(MO, xy)
plot(xy, col=MO, pch=19)
mo.dists <- as.matrix(dist(cbind(xy$x, xy$y)))
mo.dists.inv <- 1/mo.dists ##(Inf) Inverso de la Matriz
### Matriz de peso, el inverso de las distancias = mas lejos va a tener menos relevancia y un menor valor
diag(mo.dists.inv) <- 0
dim(mo.dists)
## [1] 150 150
mo.dists.inv[1:5, 1:5]
## 1 2 3 4 5
## 1 0.0000000 1.0000000 0.5 0.3333333 0.2500000
## 2 1.0000000 0.0000000 1.0 0.5000000 0.3333333
## 3 0.5000000 1.0000000 0.0 1.0000000 0.5000000
## 4 0.3333333 0.5000000 1.0 0.0000000 1.0000000
## 5 0.2500000 0.3333333 0.5 1.0000000 0.0000000
Moran.I(df$MO, mo.dists.inv)
## $observed
## [1] -0.009650003
##
## $expected
## [1] -0.006711409
##
## $sd
## [1] 0.007694112
##
## $p.value
## [1] 0.7025151
De acuerdo al p-valor calculado en el Indice de Moran se observa que no hay dependencia espacialo (negativa) o que estan minimamente relacionados.
Se modelo 18526 datos de conductiva electrica a dos profundidades diferentes: 75 cm y 150 cm. Para que el computador los procese de una mejor manera se dividieron en tres grupos, donde cada uno cuenta con aproximadamente 6000 datos. En cada caso se calculo el Indice de Moran para observar la autocorrelación espacial. Además, se representan graficamente donde se realizaron las medidas espacialmente.
library(readxl)
BD_MORAN <- read_excel("~/2020-2/Computacion estadistica/BD_MORAN.xlsx",
sheet = "Hoja1", col_types = c("numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric"))
View(BD_MORAN)
head(BD_MORAN, n=10)
## # A tibble: 10 x 7
## z X_WGS84 Y_WGS84 CEa_075 CEa_150 X_MCB Y_MCE
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 194. -72.5 4.20 6.17 18.1 843499. 955943.
## 2 194. -72.5 4.20 6.21 17.7 843499. 955943.
## 3 194. -72.5 4.20 6.37 18.6 843499. 955944.
## 4 194. -72.5 4.20 6.33 18.2 843498. 955944.
## 5 194. -72.5 4.20 6.41 18.2 843498. 955944.
## 6 194. -72.5 4.20 6.37 18.8 843498. 955944.
## 7 194. -72.5 4.20 6.33 18.0 843498. 955944.
## 8 193. -72.5 4.20 6.72 18.6 843497. 955944.
## 9 193. -72.5 4.20 6.48 18.7 843497. 955944.
## 10 193. -72.5 4.20 6.60 18.4 843497. 955944.
dim(BD_MORAN)
## [1] 18526 7
str(BD_MORAN)
## tibble [18,526 x 7] (S3: tbl_df/tbl/data.frame)
## $ z : num [1:18526] 194 194 194 194 194 ...
## $ X_WGS84: num [1:18526] -72.5 -72.5 -72.5 -72.5 -72.5 ...
## $ Y_WGS84: num [1:18526] 4.2 4.2 4.2 4.2 4.2 ...
## $ CEa_075: num [1:18526] 6.17 6.21 6.37 6.33 6.41 ...
## $ CEa_150: num [1:18526] 18.1 17.7 18.6 18.2 18.2 ...
## $ X_MCB : num [1:18526] 843499 843499 843499 843498 843498 ...
## $ Y_MCE : num [1:18526] 955943 955943 955944 955944 955944 ...
plot(BD_MORAN$Y_WGS84, BD_MORAN$X_WGS84, cex=0.01*BD_MORAN$CEa_075, col="red", pch=19)
### Profundidad de 75 cm
plot(BD_MORAN$Y_WGS84, BD_MORAN$X_WGS84, cex=1, col=0.3*BD_MORAN$CEa_075, pch=19)
### Profundidad de 150 cm
plot(BD_MORAN$Y_WGS84, BD_MORAN$X_WGS84, cex=1, col=0.3*BD_MORAN$CEa_150, pch=19)
library(ape)
library(readxl)
BD_MORAN_1 <- read_excel("~/2020-2/Computacion estadistica/BD_MORAN - Copia.xlsx",
sheet = "Hoja1", col_types = c("numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric"))
View(BD_MORAN_1)
head(BD_MORAN_1 , n=10)
## # A tibble: 10 x 7
## z X_WGS84 Y_WGS84 CEa_075 CEa_150 X_MCB Y_MCE
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 194. -72.5 4.20 6.17 18.1 843499. 955943.
## 2 194. -72.5 4.20 6.21 17.7 843499. 955943.
## 3 194. -72.5 4.20 6.37 18.6 843499. 955944.
## 4 194. -72.5 4.20 6.33 18.2 843498. 955944.
## 5 194. -72.5 4.20 6.41 18.2 843498. 955944.
## 6 194. -72.5 4.20 6.37 18.8 843498. 955944.
## 7 194. -72.5 4.20 6.33 18.0 843498. 955944.
## 8 193. -72.5 4.20 6.72 18.6 843497. 955944.
## 9 193. -72.5 4.20 6.48 18.7 843497. 955944.
## 10 193. -72.5 4.20 6.60 18.4 843497. 955944.
dim(BD_MORAN_1 )
## [1] 5999 7
str(BD_MORAN_1 )
## tibble [5,999 x 7] (S3: tbl_df/tbl/data.frame)
## $ z : num [1:5999] 194 194 194 194 194 ...
## $ X_WGS84: num [1:5999] -72.5 -72.5 -72.5 -72.5 -72.5 ...
## $ Y_WGS84: num [1:5999] 4.2 4.2 4.2 4.2 4.2 ...
## $ CEa_075: num [1:5999] 6.17 6.21 6.37 6.33 6.41 ...
## $ CEa_150: num [1:5999] 18.1 17.7 18.6 18.2 18.2 ...
## $ X_MCB : num [1:5999] 843499 843499 843499 843498 843498 ...
## $ Y_MCE : num [1:5999] 955943 955943 955944 955944 955944 ...
### Profundidad de 75 cm
plot(BD_MORAN_1$X_WGS84, BD_MORAN_1$Y_WGS84, cex=0.01*BD_MORAN_1$CEa_075, col="red", pch=19)
### Profundidad de 150 cm
plot(BD_MORAN_1$X_WGS84, BD_MORAN_1$Y_WGS84, cex=0.01*BD_MORAN_1$CEa_150, col="red", pch=19)
ce.dists1<-as.matrix(dist(cbind(BD_MORAN_1$X_WGS84, BD_MORAN_1$Y_WGS84)))
dim(ce.dists1)
## [1] 5999 5999
ce.dists.inv1 <-1/ce.dists1
ce.dists.inv1[is.infinite(ce.dists.inv1)] <- 0
diag(ce.dists.inv1)<-0
ce.dists.inv1[1:6, 1:6]
## 1 2 3 4 5 6
## 1 0.00 406473.8 183582.7 136552.7 99512.0 80767.51
## 2 406473.84 0.0 334028.1 205286.9 131603.4 100690.59
## 3 183582.68 334028.1 0.0 532631.2 217163.1 144140.71
## 4 136552.66 205286.9 532631.2 0.0 366652.3 197620.35
## 5 99512.00 131603.4 217163.1 366652.3 0.0 428663.73
## 6 80767.51 100690.6 144140.7 197620.4 428663.7 0.00
## Indice de Moran de conductividad electrica a 75 cm de profundidad
I.Moran1_75<-Moran.I(BD_MORAN_1$CEa_075, ce.dists.inv1); I.Moran1_75
## $observed
## [1] 0.5138156
##
## $expected
## [1] -0.0001667222
##
## $sd
## [1] 0.001570002
##
## $p.value
## [1] 0
## Indice de Moran de conductividad electrica a 150 cm de profundidad
I.Moran1_150<-Moran.I(BD_MORAN_1$CEa_150, ce.dists.inv1); I.Moran1_150
## $observed
## [1] 0.3309809
##
## $expected
## [1] -0.0001667222
##
## $sd
## [1] 0.001569744
##
## $p.value
## [1] 0
BD_MORAN_2 <- read_excel("~/2020-2/Computacion estadistica/BD_MORAN - Copia.xlsx",
sheet = "Hoja2", col_types = c("numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric"))
View(BD_MORAN_2)
head(BD_MORAN_2 , n=10)
## # A tibble: 10 x 7
## z X_WGS84 Y_WGS84 CEa_075 CEa_150 X_MCB Y_MCE
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 201. -72.5 4.20 10.5 19.7 843507. 956121.
## 2 201. -72.5 4.20 10.5 19.5 843507. 956121.
## 3 201. -72.5 4.20 10.6 20.1 843508. 956122.
## 4 201. -72.5 4.20 10.5 19.9 843508. 956122.
## 5 201. -72.5 4.20 10.2 19.9 843508. 956122.
## 6 201. -72.5 4.20 10.2 19.9 843509. 956122.
## 7 201. -72.5 4.20 10.6 20.1 843509. 956123.
## 8 201. -72.5 4.20 10.4 19.6 843509. 956123.
## 9 201. -72.5 4.20 10.4 19.2 843510. 956123.
## 10 201. -72.5 4.20 10.5 19.7 843510. 956124.
dim(BD_MORAN_2)
## [1] 6000 7
str(BD_MORAN_2)
## tibble [6,000 x 7] (S3: tbl_df/tbl/data.frame)
## $ z : num [1:6000] 201 201 201 201 201 ...
## $ X_WGS84: num [1:6000] -72.5 -72.5 -72.5 -72.5 -72.5 ...
## $ Y_WGS84: num [1:6000] 4.2 4.2 4.2 4.2 4.2 ...
## $ CEa_075: num [1:6000] 10.5 10.5 10.6 10.5 10.2 ...
## $ CEa_150: num [1:6000] 19.7 19.5 20.1 19.9 19.9 ...
## $ X_MCB : num [1:6000] 843507 843507 843508 843508 843508 ...
## $ Y_MCE : num [1:6000] 956121 956121 956122 956122 956122 ...
### Profundidad de 75 cm
plot(BD_MORAN_2$X_WGS84, BD_MORAN_2$Y_WGS84, cex=0.01*BD_MORAN_2$CEa_075, col="red", pch=19)
### Profundidad de 150 cm
plot(BD_MORAN_2$X_WGS84, BD_MORAN_2$Y_WGS84, cex=0.01*BD_MORAN_2$CEa_150, col="red", pch=19)
ce.dists2<-as.matrix(dist(cbind(BD_MORAN_2$X_WGS84, BD_MORAN_2$Y_WGS84)))
dim(ce.dists2)
## [1] 6000 6000
ce.dists.inv2 <-1/ce.dists2
ce.dists.inv2[is.infinite(ce.dists.inv2)] <- 0
diag(ce.dists.inv2)<-0
ce.dists.inv2[1:6, 1:6]
## 1 2 3 4 5 6
## 1 0.00 310158.42 129663.3 91605.67 70889.74 54871.26
## 2 310158.42 0.00 222810.0 130001.76 91892.63 66665.19
## 3 129663.30 222810.01 0.0 312102.51 156393.25 95127.50
## 4 91605.67 130001.76 312102.5 0.00 313473.46 136833.86
## 5 70889.74 91892.63 156393.2 313473.46 0.00 242832.20
## 6 54871.26 66665.19 95127.5 136833.86 242832.20 0.00
## Indice de Moran de conductividad electrica a 75 cm de profundidad
I.Moran2_75<-Moran.I(BD_MORAN_2$CEa_075, ce.dists.inv2); I.Moran2_75
## $observed
## [1] 0.6147608
##
## $expected
## [1] -0.0001666944
##
## $sd
## [1] 0.001342329
##
## $p.value
## [1] 0
## Indice de Moran de conductividad electrica a 150 cm de profundidad
I.Moran2_150<-Moran.I(BD_MORAN_2$CEa_150, ce.dists.inv2); I.Moran2_150
## $observed
## [1] 0.3012973
##
## $expected
## [1] -0.0001666944
##
## $sd
## [1] 0.001342245
##
## $p.value
## [1] 0
BD_MORAN_3 <- read_excel("~/2020-2/Computacion estadistica/BD_MORAN - Copia.xlsx",
sheet = "Hoja3", col_types = c("numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric"))
View(BD_MORAN_3)
head(BD_MORAN_3 , n=10)
## # A tibble: 10 x 7
## z X_WGS84 Y_WGS84 CEa_075 CEa_150 X_MCB Y_MCE
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 208. -72.5 4.20 11.2 18.0 843648. 956381.
## 2 208. -72.5 4.20 11.1 18.1 843648. 956382.
## 3 208. -72.5 4.20 11.1 18.0 843649. 956382.
## 4 208. -72.5 4.20 11.2 18.2 843649. 956382.
## 5 208. -72.5 4.20 11.3 18.2 843650. 956383.
## 6 208. -72.5 4.20 10.8 18.0 843650. 956383.
## 7 208. -72.5 4.20 11.1 18.4 843651. 956384.
## 8 208. -72.5 4.20 11.2 18.0 843651. 956384.
## 9 208. -72.5 4.20 11.6 18.3 843652. 956384.
## 10 208. -72.5 4.20 11.7 18.6 843652. 956385.
dim(BD_MORAN_3)
## [1] 6527 7
str(BD_MORAN_3)
## tibble [6,527 x 7] (S3: tbl_df/tbl/data.frame)
## $ z : num [1:6527] 208 208 208 208 208 ...
## $ X_WGS84: num [1:6527] -72.5 -72.5 -72.5 -72.5 -72.5 ...
## $ Y_WGS84: num [1:6527] 4.2 4.2 4.2 4.2 4.2 ...
## $ CEa_075: num [1:6527] 11.2 11.1 11.1 11.2 11.3 ...
## $ CEa_150: num [1:6527] 18 18.1 18 18.2 18.2 ...
## $ X_MCB : num [1:6527] 843648 843648 843649 843649 843650 ...
## $ Y_MCE : num [1:6527] 956381 956382 956382 956382 956383 ...
### Profundidad de 75 cm
plot(BD_MORAN_3$X_WGS84, BD_MORAN_3$Y_WGS84, cex=0.01*BD_MORAN_3$CEa_075, col="red", pch=19)
### Profundidad de 150 cm
plot(BD_MORAN_3$X_WGS84, BD_MORAN_3$Y_WGS84, cex=0.01*BD_MORAN_3$CEa_150, col="red", pch=19)
ce.dists3<-as.matrix(dist(cbind(BD_MORAN_3$X_WGS84, BD_MORAN_3$Y_WGS84)))
dim(ce.dists3)
## [1] 6527 6527
ce.dists.inv3 <-1/ce.dists3
ce.dists.inv3[is.infinite(ce.dists.inv3)] <- 0
diag(ce.dists.inv3)<-0
ce.dists.inv3[1:6, 1:6]
## 1 2 3 4 5 6
## 1 0.00 153846.15 81143.90 60735.31 42442.36 36671.26
## 2 153846.15 0.00 171709.56 100349.37 58608.55 48145.03
## 3 81143.90 171709.56 0.00 241412.12 88965.96 66895.51
## 4 60735.31 100349.37 241412.12 0.00 140885.18 92537.63
## 5 42442.36 58608.55 88965.96 140885.18 0.00 269655.43
## 6 36671.26 48145.03 66895.51 92537.63 269655.43 0.00
## Indice de Moran de conductividad electrica a 75 cm de profundidad
I.Moran3_75<-Moran.I(BD_MORAN_3$CEa_075, ce.dists.inv3); I.Moran3_75
## $observed
## [1] 0.4490286
##
## $expected
## [1] -0.0001532332
##
## $sd
## [1] 0.001302786
##
## $p.value
## [1] 0
## Indice de Moran de conductividad electrica a 150 cm de profundidad
I.Moran3_150<-Moran.I(BD_MORAN_3$CEa_150, ce.dists.inv3); I.Moran3_150
## $observed
## [1] 0.4800518
##
## $expected
## [1] -0.0001532332
##
## $sd
## [1] 0.00130293
##
## $p.value
## [1] 0
library(dplyr)
bind_rows(I.Moran1_75, I.Moran2_75, I.Moran3_75, id=NULL)
## # A tibble: 3 x 4
## observed expected sd p.value
## <dbl> <dbl> <dbl> <dbl>
## 1 0.514 -0.000167 0.00157 0
## 2 0.615 -0.000167 0.00134 0
## 3 0.449 -0.000153 0.00130 0
bind_rows(I.Moran1_150, I.Moran2_150, I.Moran3_150, id=NULL)
## # A tibble: 3 x 4
## observed expected sd p.value
## <dbl> <dbl> <dbl> <dbl>
## 1 0.331 -0.000167 0.00157 0
## 2 0.301 -0.000167 0.00134 0
## 3 0.480 -0.000153 0.00130 0
De acuerdo al Indice de Moran se observa que en las tres partes del p-valor fue de 0.