knitr::opts_chunk$set(echo = TRUE)
El indice de Moran (IM) es una de las medidas utilizadas para analizar la autocorrelación espacial, realizando una representación de la covarianza global. En el IM se tienen en cuenta los valores de las unidades de análisis determinadas a partir del criterio de vecindad (el valor de la unidad central no se considera para el cálculo), (R. Tobler’s et alt. 2019).
set.seed(12345)
MO <- rnorm(150, 3, 0.5)
xy <- expand.grid(x = seq(1, 10), y = seq(1, 15))
plot(xy, col = MO, pch = 15, cex = 2,
main = 'Distribución espacial de la materia orgánica')
MO.dists <- as.matrix(dist(cbind(xy$x, xy$y)))
MO.dists.inv <- 1/MO.dists
diag(MO.dists.inv) <- 0
MO.dists[1:5, 1:5]
1 2 3 4 5
1 0 1 2 3 4
2 1 0 1 2 3
3 2 1 0 1 2
4 3 2 1 0 1
5 4 3 2 1 0
xymatrix <- as.matrix(dist(cbind(xy$x, xy$y)))
xymatrix_inv <- 1/xymatrix
diag(xymatrix_inv) <- 0
xymatrix_inv[1:10, 1:10]
1 2 3 4 5 6 7
1 0.0000000 1.0000000 0.5000000 0.3333333 0.2500000 0.2000000 0.1666667
2 1.0000000 0.0000000 1.0000000 0.5000000 0.3333333 0.2500000 0.2000000
3 0.5000000 1.0000000 0.0000000 1.0000000 0.5000000 0.3333333 0.2500000
4 0.3333333 0.5000000 1.0000000 0.0000000 1.0000000 0.5000000 0.3333333
5 0.2500000 0.3333333 0.5000000 1.0000000 0.0000000 1.0000000 0.5000000
6 0.2000000 0.2500000 0.3333333 0.5000000 1.0000000 0.0000000 1.0000000
7 0.1666667 0.2000000 0.2500000 0.3333333 0.5000000 1.0000000 0.0000000
8 0.1428571 0.1666667 0.2000000 0.2500000 0.3333333 0.5000000 1.0000000
9 0.1250000 0.1428571 0.1666667 0.2000000 0.2500000 0.3333333 0.5000000
10 0.1111111 0.1250000 0.1428571 0.1666667 0.2000000 0.2500000 0.3333333
8 9 10
1 0.1428571 0.1250000 0.1111111
2 0.1666667 0.1428571 0.1250000
3 0.2000000 0.1666667 0.1428571
4 0.2500000 0.2000000 0.1666667
5 0.3333333 0.2500000 0.2000000
6 0.5000000 0.3333333 0.2500000
7 1.0000000 0.5000000 0.3333333
8 0.0000000 1.0000000 0.5000000
9 1.0000000 0.0000000 1.0000000
10 0.5000000 1.0000000 0.0000000
Moran.I(MO, xymatrix_inv)
$observed
[1] -0.009650003
$expected
[1] -0.006711409
$sd
[1] 0.007694112
$p.value
[1] 0.7025151
library("ape")
Moran.I(MO, MO.dists.inv)
$observed
[1] -0.009650003
$expected
[1] -0.006711409
$sd
[1] 0.007694112
$p.value
[1] 0.7025151
library(readxl)
BD_MORAN <- read_excel("d:/Users/Janus/Documents/Computacion estadistica/BD_MORAN.xlsx")
head(BD_MORAN, n=20)
Longitud <- BD_MORAN$X_WGS84
Latitud <- BD_MORAN$Y_WGS84
plot(Longitud,Latitud,col ="blue",cex = 0.2,main = "Puntos de muestra de Conductivica electrica aparente (CEa)")
plot(Longitud,Latitud,col=0.3*BD_MORAN$CEa_075, main = "Conductividad Electrica Aparente a 75 cm",cex.main=0.8,cex.lab=0.8,cex.axis=0.8)
plot(Longitud,Latitud,col=0.3*BD_MORAN$CEa_150, main = "Conductividad Electrica Aparente a 150 cm",cex.main=0.8,cex.lab=0.8,cex.axis=0.8)
Longitud <- BD_MORAN$X_WGS84[1:5000]
Latitud <- BD_MORAN$Y_WGS84[1:5000]
Ce_dist <- as.matrix(dist(cbind(Longitud, Latitud)))
dim(Ce_dist)
[1] 5000 5000
Ce_dist_inv <- 1/Ce_dist
Ce_dist_inv[is.infinite(Ce_dist_inv)] <- 0
diag(Ce_dist_inv) <- 0
CEa_075_1 <- BD_MORAN$CEa_075[1:5000]
Ce_dist_inv[1:10,1:10]
1 2 3 4 5 6 7
1 0.00 406473.84 183582.68 136552.66 99512.00 80767.51 66276.45
2 406473.84 0.00 334028.09 205286.88 131603.44 100690.59 79119.77
3 183582.68 334028.09 0.00 532631.20 217163.07 144140.71 103677.22
4 136552.66 205286.88 532631.20 0.00 366652.29 197620.35 128735.53
5 99512.00 131603.44 217163.07 366652.29 0.00 428663.73 198393.56
6 80767.51 100690.59 144140.71 197620.35 428663.73 0.00 369323.16
7 66276.45 79119.77 103677.22 128735.53 198393.56 369323.16 0.00
8 57404.68 66798.00 83495.12 99016.99 135648.88 198443.56 428837.13
9 49363.96 56156.93 67505.83 77303.00 97952.59 126960.00 193437.71
10 44785.68 50307.49 59227.30 66636.81 81434.82 100529.27 138109.95
8 9 10
1 57404.68 49363.96 44785.68
2 66798.00 56156.93 50307.49
3 83495.12 67505.83 59227.30
4 99016.99 77303.00 66636.81
5 135648.88 97952.59 81434.82
6 198443.56 126960.00 100529.27
7 428837.13 193437.71 138109.95
8 0.00 352381.47 203715.00
9 352381.47 0.00 482860.83
10 203715.00 482860.83 0.00
Moran.I(CEa_075_1,Ce_dist_inv)
$observed
[1] 0.5843435
$expected
[1] -0.00020004
$sd
[1] 0.001784892
$p.value
[1] 0
Longitud <- BD_MORAN$X_WGS84[5001:10000]
Latitud <- BD_MORAN$Y_WGS84[5001:10000]
Ce_dist <- as.matrix(dist(cbind(Longitud, Latitud)))
dim(Ce_dist)
[1] 5000 5000
Ce_dist_inv <- 1/Ce_dist
Ce_dist_inv[is.infinite(Ce_dist_inv)] <- 0
diag(Ce_dist_inv) <- 0
CEa_075_1 <- BD_MORAN$CEa_075[5001:10000]
Ce_dist_inv[1:10,1:10]
1 2 3 4 5 6 7
1 0.00 211114.28 105557.14 67146.52 50907.07 38565.37 32827.27
2 211114.28 0.00 211114.28 98463.65 67083.19 47184.82 38871.55
3 105557.14 211114.28 0.00 184526.97 98327.51 60766.16 47643.88
4 67146.52 98463.65 184526.97 0.00 210489.47 90601.53 64226.45
5 50907.07 67083.19 98327.51 210489.47 0.00 159066.16 92427.56
6 38565.37 47184.82 60766.16 90601.53 159066.16 0.00 220624.26
7 32827.27 38871.55 47643.88 64226.45 92427.56 220624.26 0.00
8 27536.92 31667.42 37255.68 46679.98 59981.23 96290.96 170864.05
9 24166.24 27290.06 31341.34 37753.41 46004.28 64723.18 91593.34
10 21364.07 23769.39 26785.02 31332.98 36812.50 47897.33 61179.29
8 9 10
1 27536.92 24166.24 21364.07
2 31667.42 27290.06 23769.39
3 37255.68 31341.34 26785.02
4 46679.98 37753.41 31332.98
5 59981.23 46004.28 36812.50
6 96290.96 64723.18 47897.33
7 170864.05 91593.34 61179.29
8 0.00 197424.61 95303.43
9 197424.61 0.00 184244.25
10 95303.43 184244.25 0.00
Moran.I(CEa_075_1,Ce_dist_inv)
$observed
[1] 0.6230116
$expected
[1] -0.00020004
$sd
[1] 0.001710357
$p.value
[1] 0
Longitud <- BD_MORAN$X_WGS84[10001:18526]
Latitud <- BD_MORAN$Y_WGS84[10001:18526]
Ce_dist <- as.matrix(dist(cbind(Longitud, Latitud)))
dim(Ce_dist)
[1] 8526 8526
Ce_dist_inv <- 1/Ce_dist
Ce_dist_inv[is.infinite(Ce_dist_inv)] <- 0
diag(Ce_dist_inv) <- 0
CEa_075_1 <- BD_MORAN$CEa_075[10001:18526]
Ce_dist_inv[1:10,1:10]
1 2 3 4 5 6 7
1 0.00 96784.06 60123.33 49109.46 38403.86 32791.83 27656.57
2 96784.06 0.00 158725.16 99696.88 63666.71 49595.41 38721.36
3 60123.33 158725.16 0.00 268081.10 106308.11 72134.49 51215.40
4 49109.46 99696.88 268081.10 0.00 176167.77 98689.57 63310.51
5 38403.86 63666.71 106308.11 176167.77 0.00 224397.51 98826.34
6 32791.83 49595.41 72134.49 98689.57 224397.51 0.00 176604.04
7 27656.57 38721.36 51215.40 63310.51 98826.34 176604.04 0.00
8 24230.57 32322.75 40588.04 47829.52 65654.77 92809.07 195601.85
9 21273.47 27266.74 32922.26 37531.37 47691.77 60563.48 92172.36
10 17129.70 20813.31 23954.27 26304.66 30921.66 35863.50 45001.75
8 9 10
1 24230.57 21273.47 17129.70
2 32322.75 27266.74 20813.31
3 40588.04 32922.26 23954.27
4 47829.52 37531.37 26304.66
5 65654.77 47691.77 30921.66
6 92809.07 60563.48 35863.50
7 195601.85 92172.36 45001.75
8 0.00 174312.08 58448.07
9 174312.08 0.00 87930.51
10 58448.07 87930.51 0.00
Moran.I(CEa_075_1,Ce_dist_inv)
$observed
[1] 0.4493558
$expected
[1] -0.0001173021
$sd
[1] 0.001024234
$p.value
[1] 0
Longitud <- BD_MORAN$X_WGS84[1:5000]
Latitud <- BD_MORAN$Y_WGS84[1:5000]
Ce_dist <- as.matrix(dist(cbind(Longitud, Latitud)))
dim(Ce_dist)
[1] 5000 5000
Ce_dist_inv <- 1/Ce_dist
Ce_dist_inv[is.infinite(Ce_dist_inv)] <- 0
diag(Ce_dist_inv) <- 0
CEa_150_1 <- BD_MORAN$CEa_150[1:5000]
Ce_dist_inv[1:10,1:10]
1 2 3 4 5 6 7
1 0.00 406473.84 183582.68 136552.66 99512.00 80767.51 66276.45
2 406473.84 0.00 334028.09 205286.88 131603.44 100690.59 79119.77
3 183582.68 334028.09 0.00 532631.20 217163.07 144140.71 103677.22
4 136552.66 205286.88 532631.20 0.00 366652.29 197620.35 128735.53
5 99512.00 131603.44 217163.07 366652.29 0.00 428663.73 198393.56
6 80767.51 100690.59 144140.71 197620.35 428663.73 0.00 369323.16
7 66276.45 79119.77 103677.22 128735.53 198393.56 369323.16 0.00
8 57404.68 66798.00 83495.12 99016.99 135648.88 198443.56 428837.13
9 49363.96 56156.93 67505.83 77303.00 97952.59 126960.00 193437.71
10 44785.68 50307.49 59227.30 66636.81 81434.82 100529.27 138109.95
8 9 10
1 57404.68 49363.96 44785.68
2 66798.00 56156.93 50307.49
3 83495.12 67505.83 59227.30
4 99016.99 77303.00 66636.81
5 135648.88 97952.59 81434.82
6 198443.56 126960.00 100529.27
7 428837.13 193437.71 138109.95
8 0.00 352381.47 203715.00
9 352381.47 0.00 482860.83
10 203715.00 482860.83 0.00
Moran.I(CEa_150_1,Ce_dist_inv)
$observed
[1] 0.3531011
$expected
[1] -0.00020004
$sd
[1] 0.001784437
$p.value
[1] 0
Longitud <- BD_MORAN$X_WGS84[5001:10000]
Latitud <- BD_MORAN$Y_WGS84[5001:10000]
Ce_dist <- as.matrix(dist(cbind(Longitud, Latitud)))
dim(Ce_dist)
[1] 5000 5000
Ce_dist_inv <- 1/Ce_dist
Ce_dist_inv[is.infinite(Ce_dist_inv)] <- 0
diag(Ce_dist_inv) <- 0
CEa_150_1 <- BD_MORAN$CEa_150[5001:10000]
Ce_dist_inv[1:10,1:10]
1 2 3 4 5 6 7
1 0.00 211114.28 105557.14 67146.52 50907.07 38565.37 32827.27
2 211114.28 0.00 211114.28 98463.65 67083.19 47184.82 38871.55
3 105557.14 211114.28 0.00 184526.97 98327.51 60766.16 47643.88
4 67146.52 98463.65 184526.97 0.00 210489.47 90601.53 64226.45
5 50907.07 67083.19 98327.51 210489.47 0.00 159066.16 92427.56
6 38565.37 47184.82 60766.16 90601.53 159066.16 0.00 220624.26
7 32827.27 38871.55 47643.88 64226.45 92427.56 220624.26 0.00
8 27536.92 31667.42 37255.68 46679.98 59981.23 96290.96 170864.05
9 24166.24 27290.06 31341.34 37753.41 46004.28 64723.18 91593.34
10 21364.07 23769.39 26785.02 31332.98 36812.50 47897.33 61179.29
8 9 10
1 27536.92 24166.24 21364.07
2 31667.42 27290.06 23769.39
3 37255.68 31341.34 26785.02
4 46679.98 37753.41 31332.98
5 59981.23 46004.28 36812.50
6 96290.96 64723.18 47897.33
7 170864.05 91593.34 61179.29
8 0.00 197424.61 95303.43
9 197424.61 0.00 184244.25
10 95303.43 184244.25 0.00
Moran.I(CEa_150_1,Ce_dist_inv)
$observed
[1] 0.3476675
$expected
[1] -0.00020004
$sd
[1] 0.001710253
$p.value
[1] 0
Longitud <- BD_MORAN$X_WGS84[10001:18526]
Latitud <- BD_MORAN$Y_WGS84[10001:18526]
Ce_dist <- as.matrix(dist(cbind(Longitud, Latitud)))
dim(Ce_dist)
[1] 8526 8526
Ce_dist_inv <- 1/Ce_dist
Ce_dist_inv[is.infinite(Ce_dist_inv)] <- 0
diag(Ce_dist_inv) <- 0
CEa_150_1 <- BD_MORAN$CEa_150[10001:18526]
Ce_dist_inv[1:10,1:10]
1 2 3 4 5 6 7
1 0.00 96784.06 60123.33 49109.46 38403.86 32791.83 27656.57
2 96784.06 0.00 158725.16 99696.88 63666.71 49595.41 38721.36
3 60123.33 158725.16 0.00 268081.10 106308.11 72134.49 51215.40
4 49109.46 99696.88 268081.10 0.00 176167.77 98689.57 63310.51
5 38403.86 63666.71 106308.11 176167.77 0.00 224397.51 98826.34
6 32791.83 49595.41 72134.49 98689.57 224397.51 0.00 176604.04
7 27656.57 38721.36 51215.40 63310.51 98826.34 176604.04 0.00
8 24230.57 32322.75 40588.04 47829.52 65654.77 92809.07 195601.85
9 21273.47 27266.74 32922.26 37531.37 47691.77 60563.48 92172.36
10 17129.70 20813.31 23954.27 26304.66 30921.66 35863.50 45001.75
8 9 10
1 24230.57 21273.47 17129.70
2 32322.75 27266.74 20813.31
3 40588.04 32922.26 23954.27
4 47829.52 37531.37 26304.66
5 65654.77 47691.77 30921.66
6 92809.07 60563.48 35863.50
7 195601.85 92172.36 45001.75
8 0.00 174312.08 58448.07
9 174312.08 0.00 87930.51
10 58448.07 87930.51 0.00
Moran.I(CEa_150_1,Ce_dist_inv)
$observed
[1] 0.4248239
$expected
[1] -0.0001173021
$sd
[1] 0.001024294
$p.value
[1] 0