Ejercicio Materia Orgánica
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))
plot(xy,col=MO,pch=19)

as.data.frame(MO)
## MO
## 1 3.292764
## 2 3.354733
## 3 2.945348
## 4 2.773251
## 5 3.302944
## 6 2.091022
## 7 3.315049
## 8 2.861908
## 9 2.857920
## 10 2.540339
## 11 2.941876
## 12 3.908656
## 13 3.185314
## 14 3.260108
## 15 2.624734
## 16 3.408450
## 17 2.556821
## 18 2.834211
## 19 3.560356
## 20 3.149362
## 21 3.389811
## 22 3.727893
## 23 2.677836
## 24 2.223431
## 25 2.201145
## 26 3.902549
## 27 2.759176
## 28 3.310190
## 29 3.306062
## 30 2.918845
## 31 3.405937
## 32 4.098417
## 33 4.024595
## 34 3.816223
## 35 3.127136
## 36 3.245594
## 37 2.837957
## 38 2.168975
## 39 3.883867
## 40 3.012901
## 41 3.564255
## 42 1.809821
## 43 2.469867
## 44 3.468570
## 45 3.427226
## 46 3.730365
## 47 2.293451
## 48 3.283702
## 49 3.291594
## 50 2.346601
## 51 2.729807
## 52 3.973846
## 53 3.026795
## 54 3.175831
## 55 2.664512
## 56 3.138977
## 57 3.345586
## 58 3.411898
## 59 4.072533
## 60 1.826528
## 61 3.074796
## 62 2.328734
## 63 3.276652
## 64 3.794981
## 65 2.706560
## 66 2.083811
## 67 3.444070
## 68 3.796744
## 69 3.258427
## 70 2.352164
## 71 3.027308
## 72 2.607675
## 73 2.475324
## 74 4.165256
## 75 3.701353
## 76 3.471300
## 77 3.413129
## 78 2.594230
## 79 3.238124
## 80 3.510629
## 81 3.322692
## 82 3.521572
## 83 2.847815
## 84 4.238555
## 85 3.485610
## 86 3.933550
## 87 3.336021
## 88 2.846023
## 89 3.268262
## 90 3.412435
## 91 2.518049
## 92 2.572459
## 93 3.943473
## 94 2.804090
## 95 2.509684
## 96 3.343666
## 97 2.747478
## 98 4.078860
## 99 2.700101
## 100 2.652727
## 101 3.111963
## 102 2.421888
## 103 3.211209
## 104 2.337622
## 105 3.070542
## 106 2.731976
## 107 2.844197
## 108 3.778055
## 109 2.775983
## 110 3.160562
## 111 2.384914
## 112 2.337971
## 113 3.630621
## 114 3.659616
## 115 2.959623
## 116 2.747455
## 117 2.973923
## 118 3.314430
## 119 4.090001
## 120 2.965491
## 121 3.772432
## 122 3.660726
## 123 3.161076
## 124 3.765478
## 125 2.789380
## 126 2.420589
## 127 2.077316
## 128 3.578663
## 129 1.938225
## 130 2.401984
## 131 3.821096
## 132 3.441827
## 133 3.262438
## 134 2.407670
## 135 4.327894
## 136 2.476043
## 137 2.494439
## 138 3.334461
## 139 3.064589
## 140 2.788712
## 141 2.429868
## 142 2.353142
## 143 2.702651
## 144 2.249593
## 145 3.007928
## 146 3.270085
## 147 2.226354
## 148 3.424826
## 149 3.448007
## 150 3.069345
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
Ejercicio Conductividad Eléctrica
library(readxl)
BD_MORAN_1_ <- read_excel("D:/Kevin/Trabajos/Computacion estadistica/BD_MORAN (1).xlsx")
#View(BD_MORAN_1_)
head(BD_MORAN_1_, n=20)
## # A tibble: 20 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.
## 11 193. -72.5 4.20 6.80 18.4 843496. 955944.
## 12 193. -72.5 4.20 6.84 18.3 843496. 955944.
## 13 193. -72.5 4.20 7.11 18.4 843496. 955944.
## 14 193. -72.5 4.20 6.52 18.2 843496. 955944.
## 15 193. -72.5 4.20 6.52 18.3 843495. 955944.
## 16 193. -72.5 4.20 7.03 18.8 843495. 955944.
## 17 193. -72.5 4.20 7.11 18.1 843495. 955944.
## 18 193. -72.5 4.20 7.03 18.9 843495. 955944.
## 19 193. -72.5 4.20 7.07 19.4 843494. 955944.
## 20 193. -72.5 4.20 7.23 19.3 843494. 955944.
Longitud <- BD_MORAN_1_$X_WGS84
Latitud <- BD_MORAN_1_$Y_WGS84
plot(Longitud,Latitud,col ="blue",cex = 0.2,main = "Gráfico de Puntos de muestra")

Longitud <- BD_MORAN_1_$X_WGS84
Latitud <- BD_MORAN_1_$Y_WGS84
plot(Longitud,Latitud,col =BD_MORAN_1_$CEa_075,cex = 0.5,main = "Conductividad Eléctrica a 75cm de profundidad")

Índice de Moran - CE a 75cm [primeras 5000 muestras]
library(ape)
Longitud <- BD_MORAN_1_$X_WGS84[1:5000]
Latitud <- BD_MORAN_1_$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_1_$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
Índice de Moran - CE a 75cm [de la muestra 5001 a la 10000]
library(ape)
Longitud <- BD_MORAN_1_$X_WGS84[5001:10000]
Latitud <- BD_MORAN_1_$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_1_$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
Índice de Moran - CE a 75cm [de la muestra 10001 a la 18526]
library(ape)
Longitud <- BD_MORAN_1_$X_WGS84[10001:18526]
Latitud <- BD_MORAN_1_$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_1_$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_1_$X_WGS84
Latitud <- BD_MORAN_1_$Y_WGS84
plot(Longitud,Latitud,col =BD_MORAN_1_$CEa_150,cex = 0.5,main = "Conductividad Eléctrica a 150cm de profundidad")

Índice de Moran - CE a 150cm [primeras 5000 muestras]
library(ape)
Longitud <- BD_MORAN_1_$X_WGS84[1:5000]
Latitud <- BD_MORAN_1_$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_1_$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
Índice de Moran - CE a 150cm [de la muestra 5001 a la 10000]
library(ape)
Longitud <- BD_MORAN_1_$X_WGS84[5001:10000]
Latitud <- BD_MORAN_1_$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_1_$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
Índice de Moran - CE a 150cm [de la muestra 10001 a la 18526]
library(ape)
Longitud <- BD_MORAN_1_$X_WGS84[10001:18526]
Latitud <- BD_MORAN_1_$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_1_$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