library(dagitty)
library(ggdag)
#########################################
# crear DAG
g <- dagitty("dag{
x -> y ; z -> y
x [exposure]
y [outcome]
z [unobserved]
}")
#graficar dag
ggdag(g, layout = "circle") + theme_dag()
###################################################
####### Cargar archivo de datos
library(readr)
setwd("C:/Users/MASTER/Desktop/Proyecto_finalP/Proyecto-final/R")
Datos_caribe <- read_delim("Datos_caribe.csv",
";", escape_double = FALSE, col_types = cols(Especie = col_factor(levels = c("Ficus_colubrinae",
"Ectophylla_alba")), LatitudDecimal = col_number(),
LongitudDecimal = col_number()),
trim_ws = TRUE)
View(Datos_caribe)
#######
####### Supuestos param?tricos
# Prueba de normalidad
coo <- c(Datos_caribe$LatitudDecimal, Datos_caribe$LongitudDecimal)
area.test <- shapiro.test(coo) # Prueba Shapiro para normalidad
print(area.test) # Distribucion no normal p>
plotn <- function(x,main="Histograma de frecuencias y distribucion normal",
xlab="Especie",ylab="Variabilidad") {
min <- min(x)
max <- max(x)
media <- mean(x)
dt <- sd(x)
hist(x,freq=F,main=main,xlab=xlab,ylab=ylab)
curve(dnorm(x,media,dt), min, max,add = T,col="blue")
} ## Grafico distribucion
plotn(coo,main="Distribucion normal") # Graficamente distribucion es normal, pero la Prueba Shapirolo niega
# Prueba de homogeneidad de varianzas
bartlett.test(Datos_caribe$LatitudDecimal ~ Datos_caribe$Especie) # Las varianzas son homogeneas
bartlett.test(Datos_caribe$LongitudDecimal ~ Datos_caribe$Especie) # Las varianzas son homogeneas
# Homocedasticidad
library(car) # Para homocedasticidad
leveneTest(Datos_caribe$LatitudDecimal ~ Datos_caribe$Especie) # Las variaciones no son equivalentes
leveneTest(Datos_caribe$LongitudDecimal ~ Datos_caribe$Especie) # Las variaciones no son equivalentes
# No se pueden realizar pruebas paramatricas al incumplir supuestos de normalidad y varianzas.
####### Analisis de datos
#Cargar datos de E. alba
library(readr)
alba <- read_delim("C:/Users/MASTER/Desktop/Proyecto_finalP/Proyecto-final/R/E.alba.csv",
";", escape_double = FALSE, col_types = cols(Especie = col_factor(levels = c("Ectophylla_alba")),
LatitudDecimal = col_number(), LongitudDecimal = col_number()),
trim_ws = TRUE)
View(alba)
#Cargar datos de F. colubrinae
colu <- read_delim("C:/Users/MASTER/Desktop/Proyecto_finalP/Proyecto-final/R/F.colubrinae.csv",
";", escape_double = FALSE, col_types = cols(Especie = col_factor(levels = c("Ficus_colubrinae")),
LatitudDecimal = col_number(), LongitudDecimal = col_number()),
trim_ws = TRUE)
View(colu)
##### Matrices
#Matriz para E. alba
a <- matrix(alba$LatitudDecimal, alba$LongitudDecimal, nrow = 124, ncol = 124)
#Matriz para F. colubrinae
c <- matrix(colu$LatitudDecimal, colu$LongitudDecimal, nrow = 124, ncol = 124)
##### Mantel
library (vegan)
mantel.Ecto <-mantel(a, c, method = "pearson", permutations = 999)
mantel.Ecto
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.