candidatos <- c("Year", "anio", "Año", "Anio", "year")
encontrados <- intersect(candidatos, names(datos))
col_v2 <- if (length(encontrados) > 0) encontrados[1] else names(datos)[1]
anio <- as.integer(round(suppressWarnings(as.numeric(datos[[col_v2]]))))
anio <- anio[!is.na(anio) & is.finite(anio) & anio >= 2000]valores <- seq(from = min(anio), to = max(anio), by = 1)
ni <- as.integer(table(factor(anio, levels = valores)))
total_n <- sum(ni)
hi <- ni / total_n
porcentaje <- hi * 100
Ni_asc <- cumsum(ni)
Ni_desc <- rev(cumsum(rev(ni)))
Hi_asc_pct <- cumsum(porcentaje)
Hi_desc_pct <- rev(cumsum(rev(porcentaje)))tabla_freq <- data.frame(
Valor = as.character(valores),
ni = as.character(ni),
hi = sprintf("%.4f", hi),
`hi (%)` = sprintf("%.2f", porcentaje),
Ni_asc = as.character(Ni_asc),
`Hi (%)` = sprintf("%.2f", Hi_asc_pct),
check.names = FALSE
)
fila_total <- data.frame(
Valor = "Total",
ni = as.character(total_n),
hi = sprintf("%.4f", sum(hi)),
`hi (%)` = sprintf("%.2f", sum(porcentaje)),
Ni_asc = as.character(max(Ni_asc)),
`Hi (%)` = sprintf("%.2f", max(Hi_asc_pct)),
check.names = FALSE
)
kable(rbind(tabla_freq, fila_total), align = "c")| Valor | ni | hi | hi (%) | Ni_asc | Hi (%) |
|---|---|---|---|---|---|
| 2015 | 60 | 0.2400 | 24.00 | 60 | 24.00 |
| 2016 | 57 | 0.2280 | 22.80 | 117 | 46.80 |
| 2017 | 59 | 0.2360 | 23.60 | 176 | 70.40 |
| 2018 | 74 | 0.2960 | 29.60 | 250 | 100.00 |
| Total | 250 | 1.0000 | 100.00 | 250 | 100.00 |
las_ejes <- if (length(valores) <= 20) 1 else 2
barplot(ni, names.arg = valores, col = "skyblue3", las = las_ejes,
main = "5.1 Frecuencia absoluta (ni) - Año",
xlab = "Año (Años AAAA)", ylab = "ni",
ylim = c(0, max(ni) * 1.15))
grid(nx = NA, ny = NULL, col = "gray85", lty = "dotted")barplot(ni, names.arg = valores, col = "skyblue3", las = las_ejes,
main = "5.2 Frecuencia respecto al total - Año",
xlab = "Año (Años AAAA)", ylab = "ni",
ylim = c(0, total_n))
grid(nx = NA, ny = NULL, col = "gray85", lty = "dotted")barplot(porcentaje, names.arg = valores, col = "steelblue3", las = las_ejes,
main = "5.3 Porcentaje (%) - Año",
xlab = "Año (Años AAAA)", ylab = "Porcentaje (%)",
ylim = c(0, max(porcentaje) * 1.15))
grid(nx = NA, ny = NULL, col = "gray85", lty = "dotted")barplot(porcentaje, names.arg = valores, col = "steelblue3", las = las_ejes,
main = "5.4 Porcentaje respecto a 100% - Año",
xlab = "Año (Años AAAA)", ylab = "Porcentaje (%)",
ylim = c(0, 100))
grid(nx = NA, ny = NULL, col = "gray85", lty = "dotted")boxplot(anio, horizontal = TRUE, col = "#76D7C4", border = "black", pch = 19,
main = "6. Diagrama de caja horizontal - Año",
xlab = "Año (Años AAAA)")
grid()plot(valores, Ni_asc, type = "b", col = "orange", pch = 19, lwd = 2,
ylim = c(0, total_n), main = "7.1 Ojivas absolutas - Año",
xlab = "Año (Años AAAA)", ylab = "Frecuencia acumulada (Ni)")
lines(valores, Ni_desc, type = "b", col = "blue", pch = 19, lwd = 2)
grid(col = "gray85", lty = 1)
legend("topleft", legend = c("Ascendente", "Descendente"),
col = c("orange", "blue"), pch = 19, lty = 1, lwd = 2, bg = "white")plot(valores, Hi_asc_pct, type = "b", col = "orange", pch = 19, lwd = 2,
ylim = c(0, 100), main = "7.2 Ojivas porcentuales - Año",
xlab = "Año (Años AAAA)", ylab = "Porcentaje acumulado (%)")
lines(valores, Hi_desc_pct, type = "b", col = "blue", pch = 19, lwd = 2)
grid(col = "gray85", lty = 1)
legend("topleft", legend = c("Ascendente (%)", "Descendente (%)"),
col = c("orange", "blue"), pch = 19, lty = 1, lwd = 2, bg = "white")media_v2 <- mean(anio)
mediana_v2 <- median(anio)
moda_v2 <- paste(names(which(table(anio) == max(table(anio)))), collapse = ", ")
rango_v2 <- paste0(min(anio), " - ", max(anio))
q1_v2 <- quantile(anio, 0.25)
q3_v2 <- quantile(anio, 0.75)
ric_v2 <- IQR(anio)
atip_v2 <- unique(anio[anio < (q1_v2 - 1.5 * ric_v2) | anio > (q3_v2 + 1.5 * ric_v2)])
atip_txt <- if (length(atip_v2) == 0) "No existen" else paste(sort(atip_v2), collapse = ", ")
indicadores_v2 <- data.frame(
Indicador = c("Media", "Mediana", "Moda", "Rango", "Varianza", "Desviación estándar", "Asimetría", "Curtosis", "Valores atípicos"),
Valor = c(
sprintf("%.2f", media_v2),
sprintf("%.2f", mediana_v2),
moda_v2,
rango_v2,
sprintf("%.2f", var(anio)),
sprintf("%.2f", sd(anio)),
sprintf("%.2f", skewness(anio, type = 2)),
sprintf("%.2f", kurtosis(anio)),
atip_txt
),
stringsAsFactors = FALSE
)
kable(indicadores_v2, align = "c")| Indicador | Valor |
|---|---|
| Media | 2016.59 |
| Mediana | 2017.00 |
| Moda | 2018 |
| Rango | 2015 - 2018 |
| Varianza | 1.32 |
| Desviación estándar | 1.15 |
| Asimetría | -0.11 |
| Curtosis | -1.43 |
| Valores atípicos | No existen |
cat(paste0(
"En **n = ", total_n, "** registros válidos de **Año** (`anio`), los monitoreos se registran entre **",
min(anio), "** y **", max(anio), "**, con media de **", sprintf("%.2f", media_v2),
"**, mediana de **", sprintf("%.2f", mediana_v2), "**, moda en **", moda_v2,
"** y desviación estándar de **", sprintf("%.2f", sd(anio)), "**. Valores atípicos: **", atip_txt, "**."
))En n = 250 registros válidos de Año
(anio), los monitoreos se registran entre
2015 y 2018, con media de
2016.59, mediana de 2017.00, moda en
2018 y desviación estándar de 1.15.
Valores atípicos: No existen.