#LIBRERIAS
library(faux)
## Warning: package 'faux' was built under R version 4.2.3
##
## ************
## Welcome to faux. For support and examples visit:
## https://debruine.github.io/faux/
## - Get and set global package options with: faux_options()
## ************
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.2.3
library(spacesXYZ)
## Warning: package 'spacesXYZ' was built under R version 4.2.3
library(schemr)
## Warning in .recacheSubclasses(def@className, def, env): undefined subclass
## "unpackedMatrix" of class "AnyMatrix"; definition not updated
## Warning in .recacheSubclasses(def@className, def, env): undefined subclass
## "ndiMatrix" of class "AnyMatrix"; definition not updated
## Warning in .recacheSubclasses(def@className, def, env): undefined subclass
## "pcorMatrix" of class "AnyMatrix"; definition not updated
library(ape)
## Warning: package 'ape' was built under R version 4.2.3
library(gridExtra)
## Warning: package 'gridExtra' was built under R version 4.2.3
cc = 1000376863
set.seed(cc)
lab1 = faux::rnorm_multi(n=64,
vars=3,
mu=c(40,8,13),
sd=c(2,0.8,1.3),
r=0.6,
varnames = c("l","a","b"))
lab2 = faux::rnorm_multi(n=64,
vars=3,
mu=c(39,23,-3),
sd=c(2,1.2,1),
r=0.6,
varnames = c("l","a","b"))
#GRILLA 8x8
xy = expand.grid(x=1:8,y=1:8)
plot(xy)
#NUEVOS DATOS PARA AĆADIR DISTRIBUCIĆN DE LA GRILLA
lab1_copy <- lab1
lab1_copy$grid_x <- rep(1:8, each = 8)
lab1_copy$grid_y <- rep(1:8, times = 8)
#NUEVA COLUMNA CON LOS VALORES DEL COLOR EN FORMATO HEX
lab1_copy$hex <- schemr::lab_to_hex(lab1)
g1 = ggplot(lab1_copy, aes(x = grid_x, y = grid_y, fill = hex, )) +
geom_tile() +
labs(title = "Distribución LAB1",
x = "x",
y = "y") +
theme_minimal()+
theme(legend.position = "none")
lab2_copy <- lab2
lab2_copy$grid_x <- rep(1:8, each = 8)
lab2_copy$grid_y <- rep(1:8, times = 8)
lab2_copy$hex <- schemr::lab_to_hex(lab2)
g2 = ggplot(lab2_copy, aes(x = grid_x, y = grid_y, fill = hex, )) +
geom_tile() +
labs(title = "Distribución LAB2",
x = "x",
y = "y") +
theme_minimal()+
theme(legend.position = "none")
grid.arrange(g1, g2, ncol = 2)
# Calculo de DELTAE
lab1_matrix <- as.matrix(lab1)
lab2_matrix <- as.matrix(lab2)
deltae <- as.data.frame(DeltaE(lab1_matrix, lab2_matrix, metric = "1976"))
colnames(deltae) <- "delta"
#Añadir distribución espacial a los valores de DELTAE
deltae_copy <- deltae
deltae_copy$grid_x <- rep(1:8, each = 8)
deltae_copy$grid_y <- rep(1:8, times = 8)
ggplot(deltae_copy, aes(x = grid_x, y = grid_y)) +
geom_point(aes(size = delta, color = delta)) +
geom_text(aes(label = round(delta, 2)), vjust = -1.3, size = 3)+
labs(title = "DELTAE",
x = "x",
y = "y") +
theme_minimal()+
scale_color_gradientn(colors = c("green", "red"))+
guides(size = "none")
m_dist=as.matrix(dist(cbind(deltae_copy$grid_x,deltae_copy$grid_y)))
m_delta=1/m_dist
diag(m_delta)<-0
w=m_delta
Moran.I(deltae$delta,w)
## $observed
## [1] 0.0009391808
##
## $expected
## [1] -0.01587302
##
## $sd
## [1] 0.01483683
##
## $p.value
## [1] 0.2571558