3. TABLA DE
DISTRIBUCIÓN DE FRECUENCIAS SIMPLES Y ACUMULADAS
# Número de observaciones
n_lat <- length(latitud)
# Número de intervalos (Regla de Sturges)
k_lat <- round(1 + 3.322 * log10(n_lat))
# Cálculo del rango
rango_lat <- max(latitud) - min(latitud)
# Cálculo de la amplitud
amplitud_lat <- rango_lat / k_lat
# Presentación de resultados
n_lat
## [1] 1137
k_lat
## [1] 11
rango_lat
## [1] 111.8825
amplitud_lat
## [1] 10.17114
# Límites de los intervalos
limites_lat <- seq(min(latitud),
min(latitud) + k_lat * amplitud_lat,
length.out = k_lat + 1)
# Crear intervalos
intervalos_lat <- cut(latitud,
breaks = limites_lat,
include.lowest = TRUE,
right = TRUE)
# Tabla de frecuencias
tabla_lat <- as.data.frame(table(intervalos_lat))
# Cambiar nombres de columnas
names(tabla_lat) <- c("Intervalos", "fi")
# Marca de clase
tabla_lat$xi <- (limites_lat[-length(limites_lat)] +
limites_lat[-1]) / 2
# Frecuencia acumulada
tabla_lat$Fi <- cumsum(tabla_lat$fi)
# Frecuencia relativa
tabla_lat$hi <- tabla_lat$fi / n_lat
# Frecuencia relativa acumulada
tabla_lat$Hi <- cumsum(tabla_lat$hi)
# Mostrar tabla
tabla_lat
## Intervalos fi xi Fi hi Hi
## 1 [-43.7,-33.5] 9 -38.620832 9 0.007915567 0.007915567
## 2 (-33.5,-23.4] 39 -28.449695 48 0.034300792 0.042216359
## 3 (-23.4,-13.2] 38 -18.278559 86 0.033421284 0.075637643
## 4 (-13.2,-3.02] 36 -8.107423 122 0.031662269 0.107299912
## 5 (-3.02,7.15] 27 2.063714 149 0.023746702 0.131046614
## 6 (7.15,17.3] 73 12.234850 222 0.064204046 0.195250660
## 7 (17.3,27.5] 94 22.405986 316 0.082673703 0.277924362
## 8 (27.5,37.7] 554 32.577123 870 0.487247142 0.765171504
## 9 (37.7,47.8] 156 42.748259 1026 0.137203166 0.902374670
## 10 (47.8,58] 85 52.919395 1111 0.074758135 0.977132806
## 11 (58,68.2] 26 63.090532 1137 0.022867194 1.000000000
# Presentación de la tabla de frecuencias
tabla_lat %>%
gt() %>%
tab_header(
title = "Tabla de distribución de frecuencias de Latitud",
subtitle = "Sismos registrados a nivel global (n = 1137)"
) %>%
cols_label(
Intervalos = "Intervalos",
xi = "Marca de clase (xi)",
fi = "Frecuencia simple (fi)",
Fi = "Frecuencia acumulada (Fi)",
hi = "Frecuencia relativa (hi)",
Hi = "Frecuencia relativa acumulada (Hi)"
) %>%
fmt_number(
columns = c(xi, hi, Hi),
decimals = 4
) %>%
fmt_integer(
columns = c(fi, Fi)
)
| Tabla de distribución de frecuencias de Latitud |
| Sismos registrados a nivel global (n = 1137) |
| Intervalos |
Frecuencia simple (fi) |
Marca de clase (xi) |
Frecuencia acumulada (Fi) |
Frecuencia relativa (hi) |
Frecuencia relativa acumulada (Hi) |
| [-43.7,-33.5] |
9 |
−38.6208 |
9 |
0.0079 |
0.0079 |
| (-33.5,-23.4] |
39 |
−28.4497 |
48 |
0.0343 |
0.0422 |
| (-23.4,-13.2] |
38 |
−18.2786 |
86 |
0.0334 |
0.0756 |
| (-13.2,-3.02] |
36 |
−8.1074 |
122 |
0.0317 |
0.1073 |
| (-3.02,7.15] |
27 |
2.0637 |
149 |
0.0237 |
0.1310 |
| (7.15,17.3] |
73 |
12.2349 |
222 |
0.0642 |
0.1953 |
| (17.3,27.5] |
94 |
22.4060 |
316 |
0.0827 |
0.2779 |
| (27.5,37.7] |
554 |
32.5771 |
870 |
0.4872 |
0.7652 |
| (37.7,47.8] |
156 |
42.7483 |
1,026 |
0.1372 |
0.9024 |
| (47.8,58] |
85 |
52.9194 |
1,111 |
0.0748 |
0.9771 |
| (58,68.2] |
26 |
63.0905 |
1,137 |
0.0229 |
1.0000 |
4. GRÁFICAS DE
DISTRIBUCIÓN DE FRECUENCIA
# HISTOGRAMA LOCAL - FRECUENCIAS ABSOLUTAS
# Construir histograma con los intervalos establecidos
hist_lat <- hist(latitud,
breaks = limites_lat,
right = TRUE,
include.lowest = TRUE,
plot = FALSE)
# Dibujar histograma local
plot(hist_lat,
main = "Gráfica 1: Histograma local de Latitud",
xlab = "Latitud (grados)",
ylab = "Frecuencia absoluta (fi)",
col = "lightcoral",
border = "white",
xaxt = "n",
ylim = c(0, max(hist_lat$counts) * 1.2))
# Personalizar eje horizontal
axis(1,
at = limites_lat,
labels = round(limites_lat, 2),
las = 2,
cex.axis = 0.7)

# HISTOGRAMA GLOBAL - FRECUENCIAS ABSOLUTAS
hist(latitud,
breaks = limites_lat,
main = "Gráfica 2: Histograma global de Latitud",
xlab = "Latitud (grados)",
ylab = "Frecuencia absoluta (fi)",
col = "steelblue",
border = "white",
xaxt = "n",
ylim = c(0, n_lat))
# Personalizar eje horizontal
axis(1,
at = limites_lat,
labels = round(limites_lat, 2),
las = 2,
cex.axis = 0.7)

# HISTOGRAMA LOCAL - FRECUENCIAS RELATIVAS
# Crear histograma
hist_rel_lat <- hist(latitud,
breaks = limites_lat,
plot = FALSE)
# Convertir frecuencias absolutas en relativas
hist_rel_lat$counts <- hist_rel_lat$counts / n_lat
# Calcular escala del eje vertical
max_rel <- max(hist_rel_lat$counts)
# Dibujar histograma
plot(hist_rel_lat,
freq = TRUE,
main = "Gráfica 3: Histograma local de frecuencias relativas de Latitud",
xlab = "Latitud (grados)",
ylab = "Frecuencia relativa (hi)",
col = "lightgreen",
border = "white",
xaxt = "n",
yaxt = "n",
ylim = c(0, max_rel * 1.2))
# Personalizar eje horizontal
axis(1,
at = limites_lat,
labels = round(limites_lat, 2),
las = 2,
cex.axis = 0.7)
# Personalizar eje vertical
axis(2,
at = seq(0, 0.5, by = 0.1),
labels = seq(0, 0.5, by = 0.1),
las = 1)

# HISTOGRAMA GLOBAL - FRECUENCIAS RELATIVAS
# Crear histograma
hist_rel_global <- hist(latitud,
breaks = limites_lat,
plot = FALSE)
# Convertir frecuencias absolutas en relativas
hist_rel_global$counts <- hist_rel_global$counts / n_lat
# Dibujar histograma global
plot(hist_rel_global,
freq = TRUE,
main = "Gráfica 4: Histograma global de frecuencias relativas de Latitud",
xlab = "Latitud (grados)",
ylab = "Frecuencia relativa (hi)",
col = "gold",
border = "white",
xaxt = "n",
yaxt = "n",
ylim = c(0, 1))
# Personalizar eje horizontal
axis(1,
at = limites_lat,
labels = round(limites_lat, 2),
las = 2,
cex.axis = 0.7)
# Personalizar eje vertical
axis(2,
at = seq(0, 1, by = 0.1),
labels = seq(0, 1, by = 0.1),
las = 1)

# OJIVAS - FRECUENCIAS ABSOLUTAS
# Frecuencia acumulada descendente
Ni_desc_lat <- rev(cumsum(rev(tabla_lat$fi)))
# Ojiva ascendente
plot(tabla_lat$xi, tabla_lat$Fi,
type = "b",
main = "Gráfica 5: Ojivas combinadas de frecuencias absolutas de Latitud",
xlab = "Latitud (grados)",
ylab = "Frecuencia absoluta acumulada (Fi)",
col = "blue",
lwd = 2,
pch = 16,
cex = 1.2,
las = 1,
ylim = c(0, n_lat))
# Ojiva descendente
lines(tabla_lat$xi, Ni_desc_lat,
type = "b",
col = "red",
lwd = 2,
pch = 16,
cex = 1.2)
# Leyenda
legend("left",
inset = c(0.02, 0),
legend = c("Ascendente (%)", "Descendente(%)"),
col = c("blue", "red"),
lty = 1,
lwd = 2,
pch = 16,
bty = "n")
# Cuadrícula
grid(col = "gray", lty = "dotted")

# OJIVAS - FRECUENCIAS RELATIVAS
Hi_desc_lat <- rev(cumsum(rev(tabla_lat$hi)))
plot(tabla_lat$xi, tabla_lat$Hi,
type = "b",
main = "Gráfica 6: Ojivas combinadas de frecuencias relativas de Latitud",
xlab = "Latitud (grados)",
ylab = "Frecuencia relativa acumulada",
col = "blue",
lwd = 2,
pch = 16,
cex = 1.2,
las = 1,
ylim = c(0, 1))
lines(tabla_lat$xi, Hi_desc_lat,
type = "b",
col = "red",
lwd = 2,
pch = 16,
cex = 1.2)
legend("left",
inset = c(0.02, 0),
legend = c("Ascendente (%)", "Descendente (%)"),
col = c("blue", "red"),
lty = 1,
lwd = 2,
pch = 16,
bty = "n")
grid(col = "gray", lty = "dotted")

# DIAGRAMA DE CAJA
boxplot(latitud,
main = "Gráfica 7: Diagrama de caja de Latitud",
xlab = "Latitud (grados)",
col = "lightblue",
border = "blue",
horizontal = TRUE,
las = 1)

# HISTOGRAMA CON DIAGRAMA DE CAJA SOBREPUESTO
par(mar = c(5, 5, 4, 2))
hist(latitud,
breaks = limites_lat,
main = "Gráfica 8: Histograma con diagrama de caja de Latitud",
xlab = "Latitud (grados)",
ylab = "Frecuencia absoluta",
col = "lightcoral",
border = "white",
xaxt = "n")
axis(1,
at = limites_lat,
labels = round(limites_lat, 2),
las = 2,
cex.axis = 0.7)
boxplot(latitud,
horizontal = TRUE,
add = TRUE,
at = 0,
boxwex = 0.08,
col = "lightblue",
border = "blue",
axes = FALSE)

par(mar = c(5, 4, 4, 2))
# HISTOGRAMA CON POLÍGONO DE FRECUENCIAS RELATIVAS
hist_rel_pol_lat <- hist(latitud,
breaks = limites_lat,
plot = FALSE)
hist_rel_pol_lat$counts <- hist_rel_pol_lat$counts / n_lat
plot(hist_rel_pol_lat,
main = "Gráfica 9: Histograma con polígono de frecuencias relativas de Latitud",
xlab = "Latitud (grados)",
ylab = "Frecuencia relativa (hi)",
col = "lightblue",
border = "white",
ylim = c(0, 0.55),
xaxt = "n",
yaxt = "n")
axis(1,
at = limites_lat,
labels = round(limites_lat, 2),
las = 2,
cex.axis = 0.7)
axis(2,
at = seq(0, 0.5, by = 0.1),
labels = seq(0, 0.5, by = 0.1),
las = 1)
lines(tabla_lat$xi,
tabla_lat$hi,
type = "b",
col = "red",
lwd = 2,
pch = 16)
grid(col = "gray", lty = "dotted")
