library(readxl)
df<- read_excel("C:/Users/lufca/OneDrive/Escritorio/Tesis/consolidad_filtrados.xlsx",
col_types = c("numeric", "text", "text",
"text", "text", "text", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric"))
library (dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
df %>%
group_by(Familia) %>%
summarise(
media = mean(P_Fresco, na.rm = TRUE),
mediana= median(P_Fresco, na.rm = TRUE),
desviacion = sd(P_Fresco, na.rm = TRUE),
min_P = min(P_Fresco, na.rm = TRUE),
max_P = max(P_Fresco, na.rm = TRUE)
)
## # A tibble: 15 × 6
## Familia media mediana desviacion min_P max_P
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1 73.4 66.8 57.6 0.75 364.
## 2 2 94.1 98.2 52.9 0.8 194.
## 3 3 90.9 81.2 60.1 2.7 236.
## 4 4 80.2 74 53.8 1.65 217.
## 5 5 83.1 86.2 44.3 0.6 195.
## 6 6 123. 119. 68.3 3.35 386.
## 7 7 91.2 87.8 44.4 1.85 211.
## 8 8 200. 194. 92.7 6.6 478
## 9 9 83.5 82.2 48.9 2.05 232.
## 10 10 81.0 83.9 44.7 1.75 180
## 11 11 81.0 73.1 62.6 1.2 240.
## 12 12 74.5 73.6 58.7 0.9 200.
## 13 13 153. 149. 84.5 5.5 430.
## 14 14 131. 134. 78.6 3 331.
## 15 15 132. 139. 63.0 21.1 268.
#install.packages("ggplot2")
library(ggplot2)
ggplot(data = df, aes(x = P_Fresco)) +
geom_histogram(binwidth = 4) + # Puedes ajustar el ancho de las barras según tus preferencias
facet_wrap(~ Familia, scales = "free") # Esto creará un histograma por cada familia
4. Analisis de la dependencia espacial
#install.packages("spdep")
library(spdep)
## Loading required package: spData
## The legacy packages maptools, rgdal, and rgeos, underpinning this package
## will retire shortly. Please refer to R-spatial evolution reports on
## https://r-spatial.org/r/2023/05/15/evolution4.html for details.
## This package is now running under evolution status 0
## To access larger datasets in this package, install the spDataLarge
## package with: `install.packages('spDataLarge',
## repos='https://nowosad.github.io/drat/', type='source')`
## Loading required package: sf
## Linking to GEOS 3.11.2, GDAL 3.7.2, PROJ 9.3.0; sf_use_s2() is TRUE
Revisando que no hayan duplicados
any(duplicated(df$ID))
## [1] FALSE
coordinates <- cbind(df$X, df$Y)
listw <- knn2nb(knearneigh(coordinates, k = 3), row.names = df$ID)
listw <- nb2listw(listw)
(moran <- moran.test(df$P_Fresco, listw, alternative="greater"))
##
## Moran I test under randomisation
##
## data: df$P_Fresco
## weights: listw
##
## Moran I statistic standard deviate = 10.499, p-value < 2.2e-16
## alternative hypothesis: greater
## sample estimates:
## Moran I statistic Expectation Variance
## 0.2408509658 -0.0008710801 0.0005300609