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=18)
as.data.frame(MO)
mo.dis <- as.matrix(dist(cbind(xy$x, xy$y)))
mo.dis.inv <- 1/mo.dis ##(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.dis.inv) <- 0
dim(mo.dis)
[1] 150 150
mo.dis.inv[1:10, 1:10]
1 2 3 4 5 6
1 0.0000000 1.0000000 0.5000000 0.3333333 0.2500000 0.2000000
2 1.0000000 0.0000000 1.0000000 0.5000000 0.3333333 0.2500000
3 0.5000000 1.0000000 0.0000000 1.0000000 0.5000000 0.3333333
4 0.3333333 0.5000000 1.0000000 0.0000000 1.0000000 0.5000000
5 0.2500000 0.3333333 0.5000000 1.0000000 0.0000000 1.0000000
6 0.2000000 0.2500000 0.3333333 0.5000000 1.0000000 0.0000000
7 0.1666667 0.2000000 0.2500000 0.3333333 0.5000000 1.0000000
8 0.1428571 0.1666667 0.2000000 0.2500000 0.3333333 0.5000000
9 0.1250000 0.1428571 0.1666667 0.2000000 0.2500000 0.3333333
10 0.1111111 0.1250000 0.1428571 0.1666667 0.2000000 0.2500000
7 8 9 10
1 0.1666667 0.1428571 0.1250000 0.1111111
2 0.2000000 0.1666667 0.1428571 0.1250000
3 0.2500000 0.2000000 0.1666667 0.1428571
4 0.3333333 0.2500000 0.2000000 0.1666667
5 0.5000000 0.3333333 0.2500000 0.2000000
6 1.0000000 0.5000000 0.3333333 0.2500000
7 0.0000000 1.0000000 0.5000000 0.3333333
8 1.0000000 0.0000000 1.0000000 0.5000000
9 0.5000000 1.0000000 0.0000000 1.0000000
10 0.3333333 0.5000000 1.0000000 0.0000000
Moran.I(df$MO, mo.dis.inv)
$observed
[1] -0.009650003
$expected
[1] -0.006711409
$sd
[1] 0.007694112
$p.value
[1] 0.7025151
No hay dependencia espacial según el p.value al calcular el Indice de Moran.
library(readxl)
BD_MORAN <- read_excel("./BD_MORAN.xlsx",
sheet = "Hoja1")
View(BD_MORAN)
plot(BD_MORAN$X_WGS84,BD_MORAN$Y_WGS84,col=0.5*BD_MORAN$z)
plot(BD_MORAN$X_WGS84,BD_MORAN$Y_WGS84,col=0.5*BD_MORAN$CEa_075)
plot(BD_MORAN$X_WGS84,BD_MORAN$Y_WGS84,col=0.5*BD_MORAN$CEa_150)
plot(BD_MORAN$Y_WGS84,BD_MORAN$X_WGS84,col=0.5*BD_MORAN$Y_MCE)
library(ape)
Longitud <- BD_MORAN$X_WGS84[1:4000]
Latitud <- BD_MORAN$Y_WGS84[1:4000]
Ce_dist <- as.matrix(dist(cbind(Longitud, Latitud)))
dim(Ce_dist)
[1] 4000 4000
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:4000]
Ce_dist_inv[1:10,1:10]
1 2 3 4 5 6
1 0.00 406473.84 183582.68 136552.66 99512.00 80767.51
2 406473.84 0.00 334028.09 205286.88 131603.44 100690.59
3 183582.68 334028.09 0.00 532631.20 217163.07 144140.71
4 136552.66 205286.88 532631.20 0.00 366652.29 197620.35
5 99512.00 131603.44 217163.07 366652.29 0.00 428663.73
6 80767.51 100690.59 144140.71 197620.35 428663.73 0.00
7 66276.45 79119.77 103677.22 128735.53 198393.56 369323.16
8 57404.68 66798.00 83495.12 99016.99 135648.88 198443.56
9 49363.96 56156.93 67505.83 77303.00 97952.59 126960.00
10 44785.68 50307.49 59227.30 66636.81 81434.82 100529.27
7 8 9 10
1 66276.45 57404.68 49363.96 44785.68
2 79119.77 66798.00 56156.93 50307.49
3 103677.22 83495.12 67505.83 59227.30
4 128735.53 99016.99 77303.00 66636.81
5 198393.56 135648.88 97952.59 81434.82
6 369323.16 198443.56 126960.00 100529.27
7 0.00 428837.13 193437.71 138109.95
8 428837.13 0.00 352381.47 203715.00
9 193437.71 352381.47 0.00 482860.83
10 138109.95 203715.00 482860.83 0.00
Moran.I(CEa_075_1,Ce_dist_inv)
$observed
[1] 0.5692932
$expected
[1] -0.0002500625
$sd
[1] 0.002184709
$p.value
[1] 0
library(ape)
Longitud <- BD_MORAN$X_WGS84[4001:8000]
Latitud <- BD_MORAN$Y_WGS84[4001:8000]
Ce_dist <- as.matrix(dist(cbind(Longitud, Latitud)))
dim(Ce_dist)
[1] 4000 4000
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[4001:8000]
Ce_dist_inv[1:10,1:10]
1 2 3 4 5 6
1 0.00 146925.43 84295.79 53911.96 41984.94 33629.84
2 146925.43 0.00 197748.59 85158.95 58781.71 43611.86
3 84295.79 197748.59 0.00 149570.27 83645.82 55951.51
4 53911.96 85158.95 149570.27 0.00 189776.55 89391.07
5 41984.94 58781.71 83645.82 189776.55 0.00 168991.75
6 33629.84 43611.86 55951.51 89391.07 168991.75 0.00
7 27690.34 34120.66 41235.70 56931.34 81329.50 156783.54
8 23967.31 28638.85 33488.86 43150.19 55848.72 83416.21
9 21335.13 24959.33 28564.69 35307.69 43378.13 58357.84
10 18987.88 21805.81 24508.35 29311.23 34665.34 43611.31
7 8 9 10
1 27690.34 23967.31 21335.13 18987.88
2 34120.66 28638.85 24959.33 21805.81
3 41235.70 33488.86 28564.69 24508.35
4 56931.34 43150.19 35307.69 29311.23
5 81329.50 55848.72 43378.13 34665.34
6 156783.54 83416.21 58357.84 43611.31
7 0.00 178257.65 92958.93 60417.06
8 178257.65 0.00 194265.97 91392.98
9 92958.93 194265.97 0.00 172587.03
10 60417.06 91392.98 172587.03 0.00
Moran.I(CEa_075_1,Ce_dist_inv)
$observed
[1] 0.5215655
$expected
[1] -0.0002500625
$sd
[1] 0.002154601
$p.value
[1] 0
Registered S3 methods overwritten by 'htmltools':
method from
print.html tools:rstudio
print.shiny.tag tools:rstudio
print.shiny.tag.list tools:rstudio
library(ape)
Longitud <- BD_MORAN$X_WGS84[8001:1200]
Error: object 'BD_MORAN' not found