##### UNIVERSIDAD CENTRAL DEL ECUADOR #####
#### AUTOR: LEONARDO RUIZ ####
### CARRERA: INGENIERÍA EN PETROLEOS #####
##1. Carga de Datos
library(readxl)
Datos <- read_xlsx("C:/Users/LEO/Documents/Antisana/weatherdataANTISANA.csv.xlsx")
##2.Extraer la variable continua
Precipitation <- Datos$Precipitation
Precipitation <- as.numeric(Precipitation)
Precipitation <- na.omit(Precipitation)
##3. Cálculo de intervalos (sturges)
R <- max(Precipitation) - min(Precipitation)
k <- floor(1 + (3.3 * log10(length(Precipitation))))
A <- R / k
liminf <- seq(from = min(Precipitation),
by = A,
length.out = k)
limsup <- liminf + A
limsup[k] <- max(Precipitation)
MC <- (liminf + limsup) / 2
##4.Tabla de distribución de frecuencias
#4.1 Frecuencia absoluta
ni <- numeric(k)
for (i in 1:k) {
if (i == k) {
ni[i] <- sum(Precipitation >= liminf[i] & Precipitation <= limsup[i])
} else {
ni[i] <- sum(Precipitation >= liminf[i] & Precipitation < limsup[i])
}
}
#4.2 Frecuencias relativas y acumuladas
hi <- (ni / length(Precipitation)) * 100
Niasc <- cumsum(ni)
Nidsc <- rev(cumsum(rev(ni)))
Hiasc <- cumsum(hi)
Hidsc <- rev(cumsum(rev(hi)))
#4.3 Tabla de frecuencias
tabla_Precipitation <- data.frame(
Límite_Inferior = round(liminf, 2),
Límite_Superior = round(limsup, 2),
Marca_Clase = round(MC, 2),
ni = ni,
hi_porc = round(hi, 2),
Ni_asc = Niasc,
Ni_dsc = Nidsc,
Hiasc_porc = round(Hiasc, 2),
Hidsc_porc = round(Hidsc, 2))
# TABLA 1 CON GT()
library(gt)
library(dplyr)
##
## Adjuntando el paquete: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(e1071)
tabla_Precipitation %>%
gt() %>%
tab_header(
title = md("**Tabla 1: Distribución de Frecuencias de Precipitación**"),
subtitle = md("Antisana | Método Sturges")
) %>%
tab_source_note(
source_note = md("**Antisana**")
) %>%
cols_label(
Límite_Inferior = "L. Inferior",
Límite_Superior = "L. Superior",
Marca_Clase = "Marca Clase",
hi_porc = "hi %",
Ni_asc = "Ni Asc.",
Ni_dsc = "Ni Desc.",
Hiasc_porc = "Hi Asc. %",
Hidsc_porc = "Hi Desc. %"
) %>%
fmt_number(
columns = c(Límite_Inferior, Límite_Superior, Marca_Clase),
decimals = 2
) %>%
fmt_number(
columns = c(hi_porc, Hiasc_porc, Hidsc_porc),
decimals = 2,
pattern = "{x}%"
)
| Tabla 1: Distribución de Frecuencias de Precipitación |
| Antisana | Método Sturges |
| L. Inferior |
L. Superior |
Marca Clase |
ni |
hi % |
Ni Asc. |
Ni Desc. |
Hi Asc. % |
Hi Desc. % |
| 0.01 |
10.53 |
5.27 |
158 |
43.17% |
158 |
366 |
43.17% |
100.00% |
| 10.53 |
21.06 |
15.79 |
89 |
24.32% |
247 |
208 |
67.49% |
56.83% |
| 21.06 |
31.58 |
26.32 |
56 |
15.30% |
303 |
119 |
82.79% |
32.51% |
| 31.58 |
42.10 |
36.84 |
33 |
9.02% |
336 |
63 |
91.80% |
17.21% |
| 42.10 |
52.63 |
47.36 |
16 |
4.37% |
352 |
30 |
96.17% |
8.20% |
| 52.63 |
63.15 |
57.89 |
9 |
2.46% |
361 |
14 |
98.63% |
3.83% |
| 63.15 |
73.67 |
68.41 |
3 |
0.82% |
364 |
5 |
99.45% |
1.37% |
| 73.67 |
84.20 |
78.94 |
0 |
0.00% |
364 |
2 |
99.45% |
0.55% |
| 84.20 |
94.72 |
89.46 |
2 |
0.55% |
366 |
2 |
100.00% |
0.55% |
| Antisana |
##5. Gráficos
#5.1 Histograma
hist(Precipitation,
main = "Gráfica No.1: Distribución de Temperatura Mínima",
breaks = seq(min(Precipitation), max(Precipitation) + A, by = A),
xlab = "Precipitación (Caída de lluvia)",
ylab = "Cantidad",
col = "lightblue",
border = "darkblue",
xaxt = "n")
# Eje X personalizado con MARCAS DE CLASE
axis(1, at = MC, # Posiciones: Marcas de Clase
labels = round(MC, 2), # Etiquetas: valores redondeados
las = 1) # Etiquetas horizontales

#5.2 Ojivas
x_asc <- c(min(liminf), limsup)
y_asc <- c(0, Niasc)
x_desc <- c(liminf, max(limsup))
y_desc <- c(Nidsc, 0)
x_range <- range(c(x_asc, x_desc))
y_range <- c(0, max(c(y_asc, y_desc)))
plot(x_asc, y_asc, type = "o", col = "skyblue",
main = "Gráfica No.2: Ojivas Ascendente y Descendente de Precipitación",
xlab = "Precipitación (Caída de lluvia)",
ylab = "Frecuencia acumulada",
xlim = x_range, ylim = y_range,
xaxt = "n", pch = 16, lwd = 2)
axis(1, at = pretty(x_range),
labels = format(pretty(x_range), scientific = FALSE))
axis(2, at = pretty(y_range))
lines(x_desc, y_desc, type = "o", col = "steelblue4", pch = 17, lwd = 2)
legend("right",
legend = c("Ojiva Ascendente", "Ojiva Descendente"),
col = c("skyblue", "steelblue4"),
pch = c(16, 17),
lty = 1,
lwd = 2,
cex = 0.8)

#5.3 Diagramas de cajas
boxplot(Precipitation,
horizontal = TRUE,
col = "steelblue",
main = "Gráfica No.3: Distribución de Precipitación",
xlab = "Precipitación (Caída de lluvia)",
xaxt = "n")
axis(1, at = pretty(Precipitation),
labels = format(pretty(Precipitation), scientific = FALSE))

# Outliers
outliers <- boxplot.stats(Precipitation)$out
cat("\nNúmero de outliers:", length(outliers), "\n")
##
## Número de outliers: 10
if(length(outliers) > 0) {
cat("Outliers:", round(outliers, 2), "\n")
}
## Outliers: 64.67 94.72 60.11 58.41 85.58 58.2 59.47 57.83 64.03 64.26
##6. Indicadores estadísticos
get_mode_interval <- function() {
idx <- which.max(ni)
return(paste0("[", round(liminf[idx], 2), ", ", round(limsup[idx], 2), "]"))
}
media <- mean(Precipitation)
mediana <- median(Precipitation)
moda_intervalo <- get_mode_interval()
desv <- sd(Precipitation)
varianza <- var(Precipitation)
cv <- (desv / media) * 100
asim <- skewness(Precipitation)
curt <- kurtosis(Precipitation)
# CREAR DATA.FRAME DE INDICADORES
indicadores <- data.frame(
Indicador = c("Mínimo", "Máximo", "Media", "Mediana", "Moda (intervalo)",
"Desviación Estándar", "Varianza", "Coef. Variación (%)",
"Asimetría", "Curtosis", "N° Outliers"),
Valor = c(round(min(Precipitation), 2), round(max(Precipitation), 2),
round(media, 2), round(mediana, 2), moda_intervalo,
round(desv, 2), round(varianza, 2), round(cv, 2),
round(asim, 2), round(curt, 2), length(outliers))
)
# TABLA 2 CON GT()
indicadores %>%
gt() %>%
tab_header(
title = md("**Tabla 2: Indicadores Estadísticos de Precipitación**")
) %>%
tab_source_note(
source_note = md("**Antisana**")
) %>%
cols_label(
Indicador = "Indicador",
Valor = "Valor"
) %>%
tab_style(
style = cell_text(weight = "bold"),
locations = cells_body(columns = Indicador)
)
| Tabla 2: Indicadores Estadísticos de Precipitación |
| Indicador |
Valor |
| Mínimo |
0.01 |
| Máximo |
94.72 |
| Media |
17.1 |
| Mediana |
12.94 |
| Moda (intervalo) |
[0.01, 10.53] |
| Desviación Estándar |
16.12 |
| Varianza |
259.7 |
| Coef. Variación (%) |
94.21 |
| Asimetría |
1.3 |
| Curtosis |
1.95 |
| N° Outliers |
10 |
| Antisana |
##7. Conclusión
#La variable Precipitation fluctúa entre 0.01 y 94.72 y sus valores están en torno a los 12.94 (media = 17.1 ), con una desviación estándar de 16.12 siendo un conjunto de valores extremadamente heterogéneos (CV = 94.21%) cuyos valores se concentran en el intervalo modal [0.01, 10.53] y con distribución leptocúrtica (K = 1.95) y sesgo pronunciado hacia la derecha (As = 1.3) a excepción de los 10 valores atípicos identificados, por lo tanto el comportamiento de la variable indica un proceso mayoritariamente inestable con mediciones consistentes en el rango principal, aunque con presencia significativa de lecturas extremas que requieren análisis particular.